Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
gitlab-ce
Commits
5ffa8f05
Commit
5ffa8f05
authored
Apr 09, 2016
by
Robert Speicher
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Escape the query argument provided to `git grep` by `search_files`
Closes #14963.
parent
600b94cd
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
7 additions
and
1 deletion
+7
-1
app/models/repository.rb
app/models/repository.rb
+1
-1
spec/models/repository_spec.rb
spec/models/repository_spec.rb
+6
-0
No files found.
app/models/repository.rb
View file @
5ffa8f05
...
...
@@ -795,7 +795,7 @@ class Repository
def
search_files
(
query
,
ref
)
offset
=
2
args
=
%W(
#{
Gitlab
.
config
.
git
.
bin_path
}
grep -i -I -n --before-context
#{
offset
}
--after-context
#{
offset
}
-e
#{
query
}
#{
ref
||
root_ref
}
)
args
=
%W(
#{
Gitlab
.
config
.
git
.
bin_path
}
grep -i -I -n --before-context
#{
offset
}
--after-context
#{
offset
}
-e
#{
Regexp
.
escape
(
query
)
}
#{
ref
||
root_ref
}
)
Gitlab
::
Popen
.
popen
(
args
,
path_to_repo
).
first
.
scrub
.
split
(
/^--$/
)
end
...
...
spec/models/repository_spec.rb
View file @
5ffa8f05
...
...
@@ -94,6 +94,12 @@ describe Repository, models: true do
it
{
is_expected
.
to
be_an
Array
}
it
'regex-escapes the query string'
do
results
=
repository
.
search_files
(
"test
\\
"
,
'master'
)
expect
(
results
.
first
).
not_to
start_with
(
'fatal:'
)
end
describe
'result'
do
subject
{
results
.
first
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment