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
Léo-Paul Géneau
gitlab-ce
Commits
8b736c91
Commit
8b736c91
authored
May 11, 2018
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement variables expression untrusted pattern lexeme
parent
6d0c10b1
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
81 additions
and
0 deletions
+81
-0
lib/gitlab/ci/pipeline/expression/lexeme/pattern.rb
lib/gitlab/ci/pipeline/expression/lexeme/pattern.rb
+26
-0
spec/lib/gitlab/ci/pipeline/expression/lexeme/pattern_spec.rb
.../lib/gitlab/ci/pipeline/expression/lexeme/pattern_spec.rb
+55
-0
No files found.
lib/gitlab/ci/pipeline/expression/lexeme/pattern.rb
0 → 100644
View file @
8b736c91
module
Gitlab
module
Ci
module
Pipeline
module
Expression
module
Lexeme
class
Pattern
<
Lexeme
::
Value
PATTERN
=
%r{/(?<regexp>.+)/}
.
freeze
def
initialize
(
regexp
)
@value
=
regexp
end
def
evaluate
(
variables
=
{})
Gitlab
::
UntrustedRegexp
.
new
(
@value
.
to_s
)
# TODO raise LexerError / ParserError in case of RegexpError
end
def
self
.
build
(
string
)
new
(
string
.
match
(
PATTERN
)[
:regexp
])
end
end
end
end
end
end
end
spec/lib/gitlab/ci/pipeline/expression/lexeme/pattern_spec.rb
0 → 100644
View file @
8b736c91
require
'fast_spec_helper'
require_dependency
're2'
describe
Gitlab
::
Ci
::
Pipeline
::
Expression
::
Lexeme
::
Pattern
do
describe
'.build'
do
it
'creates a new instance of the token'
do
expect
(
described_class
.
build
(
'/.*/'
))
.
to
be_a
(
described_class
)
end
end
describe
'.type'
do
it
'is a value lexeme'
do
expect
(
described_class
.
type
).
to
eq
:value
end
end
describe
'.scan'
do
it
'correctly identifies a pattern token'
do
scanner
=
StringScanner
.
new
(
'/pattern/'
)
token
=
described_class
.
scan
(
scanner
)
expect
(
token
).
not_to
be_nil
expect
(
token
.
build
.
evaluate
)
.
to
eq
Gitlab
::
UntrustedRegexp
.
new
(
'pattern'
)
end
it
'is a greedy scanner for regexp boundaries'
do
scanner
=
StringScanner
.
new
(
'/some .* / pattern/'
)
token
=
described_class
.
scan
(
scanner
)
expect
(
token
).
not_to
be_nil
expect
(
token
.
build
.
evaluate
)
.
to
eq
Gitlab
::
UntrustedRegexp
.
new
(
'some .* / pattern'
)
end
it
'does not allow to use an empty pattern'
do
scanner
=
StringScanner
.
new
(
%(//)
)
token
=
described_class
.
scan
(
scanner
)
expect
(
token
).
to
be_nil
end
end
describe
'#evaluate'
do
it
'returns a regular expression'
do
string
=
described_class
.
new
(
'abc'
)
expect
(
string
.
evaluate
).
to
eq
Gitlab
::
UntrustedRegexp
.
new
(
'abc'
)
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