Commit a539e03d authored by Andrew McCallum's avatar Andrew McCallum

Account for query of only forward slash(es).

parent 7ce732fb
......@@ -938,10 +938,10 @@ class Repository
end
def search_files_by_name(query, ref)
return [] if empty? || query.blank?
safe_query = query.sub(/^\/*/, "")
return [] if empty? || safe_query.blank?
args = %W(ls-tree --full-tree -r #{ref || root_ref} --name-status | #{Regexp.escape(safe_query)})
run_git(args).first.lines.map(&:strip)
......
......@@ -670,9 +670,16 @@ describe Repository do
it 'ignores leading slashes' do
results = repository.search_files_by_name('/files', 'master')
expect(results.first).to eq('files/html/500.html')
end
it 'properly handles when query is only slashes' do
results = repository.search_files_by_name('//', 'master')
expect(results).to match_array([])
end
it 'properly handles when query is not present' do
results = repository.search_files_by_name('', 'master')
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment