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
Jérome Perrin
gitlab-ce
Commits
866aab7f
Commit
866aab7f
authored
Aug 26, 2017
by
Hiroyuki Sato
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix escape characters was not sanitized
parent
9e203582
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
31 additions
and
2 deletions
+31
-2
lib/gitlab/sql/pattern.rb
lib/gitlab/sql/pattern.rb
+7
-2
spec/lib/gitlab/sql/pattern_spec.rb
spec/lib/gitlab/sql/pattern_spec.rb
+24
-0
No files found.
lib/gitlab/sql/pattern.rb
View file @
866aab7f
...
...
@@ -11,9 +11,9 @@ module Gitlab
def
to_sql
if
exact_matching?
query
sanitized_
query
else
"%
#{
query
}
%"
"%
#{
sanitized_
query
}
%"
end
end
...
...
@@ -24,6 +24,11 @@ module Gitlab
def
partial_matching?
@query
.
length
>=
MIN_CHARS_FOR_PARTIAL_MATCHING
end
def
sanitized_query
# Note: ActiveRecord::Base.sanitize_sql_like is a protected method
ActiveRecord
::
Base
.
__send__
(
:sanitize_sql_like
,
query
)
end
end
end
end
spec/lib/gitlab/sql/pattern_spec.rb
View file @
866aab7f
...
...
@@ -12,6 +12,14 @@ describe Gitlab::SQL::Pattern do
end
end
context
'when a query with a escape character is shorter than 3 chars'
do
let
(
:query
)
{
'_2'
}
it
'returns sanitized exact matching pattern'
do
expect
(
to_sql
).
to
eq
(
'\_2'
)
end
end
context
'when a query is equal to 3 chars'
do
let
(
:query
)
{
'123'
}
...
...
@@ -20,6 +28,14 @@ describe Gitlab::SQL::Pattern do
end
end
context
'when a query with a escape character is equal to 3 chars'
do
let
(
:query
)
{
'_23'
}
it
'returns partial matching pattern'
do
expect
(
to_sql
).
to
eq
(
'%\_23%'
)
end
end
context
'when a query is longer than 3 chars'
do
let
(
:query
)
{
'1234'
}
...
...
@@ -27,5 +43,13 @@ describe Gitlab::SQL::Pattern do
expect
(
to_sql
).
to
eq
(
'%1234%'
)
end
end
context
'when a query with a escape character is longer than 3 chars'
do
let
(
:query
)
{
'_234'
}
it
'returns sanitized partial matching pattern'
do
expect
(
to_sql
).
to
eq
(
'%\_234%'
)
end
end
end
end
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