From a539e03d7e4f12cfaa3ae7998dd111f498f4c8dc Mon Sep 17 00:00:00 2001 From: Andrew McCallum Date: Mon, 15 Jan 2018 15:19:43 +0000 Subject: Account for query of only forward slash(es). --- app/models/repository.rb | 4 ++-- spec/models/repository_spec.rb | 7 +++++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/app/models/repository.rb b/app/models/repository.rb index f3ec65a1885..c258cffb274 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -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) diff --git a/spec/models/repository_spec.rb b/spec/models/repository_spec.rb index 5860a0bf698..6767d818009 100644 --- a/spec/models/repository_spec.rb +++ b/spec/models/repository_spec.rb @@ -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') -- cgit v1.2.1