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
8b3e21b6
Commit
8b3e21b6
authored
May 17, 2018
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add variables expression pattern validation support
parent
a1f1e086
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
20 additions
and
1 deletion
+20
-1
lib/gitlab/ci/pipeline/expression/lexeme/pattern.rb
lib/gitlab/ci/pipeline/expression/lexeme/pattern.rb
+4
-0
spec/lib/gitlab/ci/config/entry/policy_spec.rb
spec/lib/gitlab/ci/config/entry/policy_spec.rb
+9
-1
spec/lib/gitlab/ci/pipeline/expression/lexeme/pattern_spec.rb
.../lib/gitlab/ci/pipeline/expression/lexeme/pattern_spec.rb
+7
-0
No files found.
lib/gitlab/ci/pipeline/expression/lexeme/pattern.rb
View file @
8b3e21b6
...
...
@@ -10,6 +10,10 @@ module Gitlab
def
initialize
(
regexp
)
@value
=
regexp
unless
Gitlab
::
UntrustedRegexp
.
valid?
(
@value
)
raise
Lexer
::
SyntaxError
,
'Invalid regular expression!'
end
end
def
evaluate
(
variables
=
{})
...
...
spec/lib/gitlab/ci/config/entry/policy_spec.rb
View file @
8b3e21b6
...
...
@@ -111,7 +111,15 @@ describe Gitlab::Ci::Config::Entry::Policy do
context
'when specifying invalid variables expressions token'
do
let
(
:config
)
{
{
variables:
[
'$MY_VAR == 123'
]
}
}
it
'reports an error about invalid statement'
do
it
'reports an error about invalid expression'
do
expect
(
entry
.
errors
).
to
include
/invalid expression syntax/
end
end
context
'when using invalid variables expressions regexp'
do
let
(
:config
)
{
{
variables:
[
'$MY_VAR =~ /some ( thing/'
]
}
}
it
'reports an error about invalid expression'
do
expect
(
entry
.
errors
).
to
include
/invalid expression syntax/
end
end
...
...
spec/lib/gitlab/ci/pipeline/expression/lexeme/pattern_spec.rb
View file @
8b3e21b6
...
...
@@ -6,6 +6,11 @@ describe Gitlab::Ci::Pipeline::Expression::Lexeme::Pattern do
expect
(
described_class
.
build
(
'/.*/'
))
.
to
be_a
(
described_class
)
end
it
'raises an error if pattern is invalid'
do
expect
{
described_class
.
build
(
'/ some ( thin/i'
)
}
.
to
raise_error
(
Gitlab
::
Ci
::
Pipeline
::
Expression
::
Lexer
::
SyntaxError
)
end
end
describe
'.type'
do
...
...
@@ -80,6 +85,8 @@ describe Gitlab::Ci::Pipeline::Expression::Lexeme::Pattern do
end
it
'raises error if evaluated regexp is not valid'
do
allow
(
Gitlab
::
UntrustedRegexp
).
to
receive
(
:valid?
).
and_return
(
true
)
regexp
=
described_class
.
new
(
'invalid ( .*'
)
expect
{
regexp
.
evaluate
}
...
...
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