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
1
Merge Requests
1
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
nexedi
gitlab-ce
Commits
78c6f914
Commit
78c6f914
authored
Feb 07, 2020
by
John Hope
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add negative lookahead to avoid matching incorrect commands
parent
5b5b4d87
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
4 deletions
+26
-4
lib/gitlab/quick_actions/substitution_definition.rb
lib/gitlab/quick_actions/substitution_definition.rb
+2
-2
spec/lib/gitlab/quick_actions/substitution_definition_spec.rb
.../lib/gitlab/quick_actions/substitution_definition_spec.rb
+24
-2
No files found.
lib/gitlab/quick_actions/substitution_definition.rb
View file @
78c6f914
...
...
@@ -10,14 +10,14 @@ module Gitlab
end
def
match
(
content
)
content
.
match
%r{^/
#{
all_names
.
join
(
'|'
)
}
?(.*)$}
content
.
match
%r{^/
#{
all_names
.
join
(
'|'
)
}
(?![
\S
])
?(.*)$}
end
def
perform_substitution
(
context
,
content
)
return
unless
content
all_names
.
each
do
|
a_name
|
content
=
content
.
gsub
(
%r{/
#{
a_name
}
?(.*)$}i
,
execute_block
(
action_block
,
context
,
'\1'
))
content
=
content
.
gsub
(
%r{/
#{
a_name
}
(?![
\S
])
?(.*)$}i
,
execute_block
(
action_block
,
context
,
'\1'
))
end
content
...
...
spec/lib/gitlab/quick_actions/substitution_definition_spec.rb
View file @
78c6f914
...
...
@@ -19,11 +19,29 @@ EOF
expect
(
subject
.
perform_substitution
(
self
,
nil
)).
to
be_nil
end
it
'performs the substitution by default'
do
expect
(
subject
.
perform_substitution
(
self
,
content
)).
to
eq
<<
EOF
context
'when content contains command name'
do
it
'performs the substitution by default'
do
expect
(
subject
.
perform_substitution
(
self
,
content
)).
to
eq
<<
EOF
Hello! Let's do this!
I like this stuff foo
EOF
end
end
context
'when content contains command name in word'
do
let
(
:content
)
do
<<
EOF
Hello! Let's do this!
`/sub_names` I like this stuff
EOF
end
it
'does not perform the substitution'
do
expect
(
subject
.
perform_substitution
(
self
,
content
)).
to
eq
<<
EOF
Hello! Let's do this!
`/sub_names` I like this stuff
EOF
end
end
end
...
...
@@ -41,5 +59,9 @@ EOF
it
'is nil if content does not have the command'
do
expect
(
subject
.
match
(
'blah'
)).
to
be_falsey
end
it
'is nil if content contains the command as prefix'
do
expect
(
subject
.
match
(
'/sub_namex'
)).
to
be_falsey
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