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
85333aed
Commit
85333aed
authored
Feb 27, 2018
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add support for single quoted string in pipeline expressions
parent
d3076ff0
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
64 additions
and
1 deletion
+64
-1
lib/gitlab/ci/pipeline/expression/lexeme/string.rb
lib/gitlab/ci/pipeline/expression/lexeme/string.rb
+1
-1
spec/lib/gitlab/ci/pipeline/expression/lexeme/string_spec.rb
spec/lib/gitlab/ci/pipeline/expression/lexeme/string_spec.rb
+62
-0
spec/lib/gitlab/ci/pipeline/expression/statement_spec.rb
spec/lib/gitlab/ci/pipeline/expression/statement_spec.rb
+1
-0
No files found.
lib/gitlab/ci/pipeline/expression/lexeme/string.rb
View file @
85333aed
...
...
@@ -4,7 +4,7 @@ module Gitlab
module
Expression
module
Lexeme
class
String
<
Lexeme
::
Value
PATTERN
=
/
"(?<string>.+?)"
/
.
freeze
PATTERN
=
/
("(?<string>.+?)")|('(?<string>.+?)')
/
.
freeze
def
initialize
(
value
)
@value
=
value
...
...
spec/lib/gitlab/ci/pipeline/expression/lexeme/string_spec.rb
View file @
85333aed
...
...
@@ -14,6 +14,68 @@ describe Gitlab::Ci::Pipeline::Expression::Lexeme::String do
end
end
describe
'.scan'
do
context
'when using double quotes'
do
it
'correctly identifies string token'
do
scanner
=
StringScanner
.
new
(
'"some string"'
)
token
=
described_class
.
scan
(
scanner
)
expect
(
token
).
not_to
be_nil
expect
(
token
.
build
.
evaluate
).
to
eq
'some string'
end
end
context
'when using single quotes'
do
it
'correctly identifies string token'
do
scanner
=
StringScanner
.
new
(
"'some string 2'"
)
token
=
described_class
.
scan
(
scanner
)
expect
(
token
).
not_to
be_nil
expect
(
token
.
build
.
evaluate
).
to
eq
'some string 2'
end
end
context
'when there are mixed quotes in the string'
do
it
'is a greedy scanner for double quotes'
do
scanner
=
StringScanner
.
new
(
'"some string" "and another one"'
)
token
=
described_class
.
scan
(
scanner
)
expect
(
token
).
not_to
be_nil
expect
(
token
.
build
.
evaluate
).
to
eq
'some string'
end
it
'is a greedy scanner for single quotes'
do
scanner
=
StringScanner
.
new
(
"'some string' 'and another one'"
)
token
=
described_class
.
scan
(
scanner
)
expect
(
token
).
not_to
be_nil
expect
(
token
.
build
.
evaluate
).
to
eq
'some string'
end
it
'allows to use single quotes inside double quotes'
do
scanner
=
StringScanner
.
new
(
%("some ' string")
)
token
=
described_class
.
scan
(
scanner
)
expect
(
token
).
not_to
be_nil
expect
(
token
.
build
.
evaluate
).
to
eq
"some ' string"
end
it
'allow to use double quotes inside single quotes'
do
scanner
=
StringScanner
.
new
(
%('some " string')
)
token
=
described_class
.
scan
(
scanner
)
expect
(
token
).
not_to
be_nil
expect
(
token
.
build
.
evaluate
).
to
eq
'some " string'
end
end
end
describe
'#evaluate'
do
it
'returns string value it is is present'
do
string
=
described_class
.
new
(
'my string'
)
...
...
spec/lib/gitlab/ci/pipeline/expression/statement_spec.rb
View file @
85333aed
...
...
@@ -64,6 +64,7 @@ describe Gitlab::Ci::Pipeline::Expression::Statement do
describe
'#evaluate'
do
statements
=
[
[
'$VARIABLE == "my variable"'
,
true
],
[
"$VARIABLE == 'my variable'"
,
true
],
[
'"my variable" == $VARIABLE'
,
true
],
[
'$VARIABLE == null'
,
false
],
[
'$VAR == null'
,
true
],
...
...
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