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
a1f1e086
Commit
a1f1e086
authored
May 17, 2018
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add anti-corruption layer above expressions pattern matching
parent
0ce63efe
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
30 additions
and
2 deletions
+30
-2
lib/gitlab/ci/pipeline/expression/lexeme/pattern.rb
lib/gitlab/ci/pipeline/expression/lexeme/pattern.rb
+2
-2
spec/lib/gitlab/ci/pipeline/expression/lexeme/pattern_spec.rb
.../lib/gitlab/ci/pipeline/expression/lexeme/pattern_spec.rb
+28
-0
No files found.
lib/gitlab/ci/pipeline/expression/lexeme/pattern.rb
View file @
a1f1e086
...
...
@@ -6,14 +6,14 @@ module Gitlab
require_dependency
're2'
class
Pattern
<
Lexeme
::
Value
PATTERN
=
%r{
/(?<regexp>.+)/
}
.
freeze
PATTERN
=
%r{
^(?<regexp>/.+/[ismU]*)$
}
.
freeze
def
initialize
(
regexp
)
@value
=
regexp
end
def
evaluate
(
variables
=
{})
Gitlab
::
UntrustedRegexp
.
new
(
@value
)
Gitlab
::
UntrustedRegexp
.
fabricate
(
@value
)
rescue
RegexpError
raise
Expression
::
RuntimeError
,
'Invalid regular expression!'
end
...
...
spec/lib/gitlab/ci/pipeline/expression/lexeme/pattern_spec.rb
View file @
a1f1e086
...
...
@@ -42,6 +42,34 @@ describe Gitlab::Ci::Pipeline::Expression::Lexeme::Pattern do
expect
(
token
).
to
be_nil
end
it
'support single flag'
do
scanner
=
StringScanner
.
new
(
'/pattern/i'
)
token
=
described_class
.
scan
(
scanner
)
expect
(
token
).
not_to
be_nil
expect
(
token
.
build
.
evaluate
)
.
to
eq
Gitlab
::
UntrustedRegexp
.
new
(
'(?i)pattern'
)
end
it
'support multiple flags'
do
scanner
=
StringScanner
.
new
(
'/pattern/im'
)
token
=
described_class
.
scan
(
scanner
)
expect
(
token
).
not_to
be_nil
expect
(
token
.
build
.
evaluate
)
.
to
eq
Gitlab
::
UntrustedRegexp
.
new
(
'(?im)pattern'
)
end
it
'does not support arbitrary flags'
do
scanner
=
StringScanner
.
new
(
'/pattern/x'
)
token
=
described_class
.
scan
(
scanner
)
expect
(
token
).
to
be_nil
end
end
describe
'#evaluate'
do
...
...
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