Make variables expression pattern case-sensitivity explicit

This commit is contained in:
Grzegorz Bizon 2018-05-15 15:18:18 +02:00
parent 73aee958e2
commit f52de2f73c
3 changed files with 22 additions and 0 deletions

View file

@ -537,6 +537,12 @@ Below you can find supported syntax reference:
It is possible perform pattern matching against a variable and regular It is possible perform pattern matching against a variable and regular
expression. Expression like this evaluates to truth if matches are found. expression. Expression like this evaluates to truth if matches are found.
Pattern matching is case-sensitive by default. Prepend `(?i)` to a
match-group to make a pattern case-insensitive.
Under the hood we are using [RE2 library][re2-library], see
[syntax documentation][re2-syntax] for reference.
### Unsupported predefined variables ### Unsupported predefined variables
Because GitLab evaluates variables before creating jobs, we do not support a Because GitLab evaluates variables before creating jobs, we do not support a
@ -577,3 +583,5 @@ These variables are also not supported in a context of a
[builds-policies]: ../yaml/README.md#only-and-except-complex [builds-policies]: ../yaml/README.md#only-and-except-complex
[dynamic-environments]: ../environments.md#dynamic-environments [dynamic-environments]: ../environments.md#dynamic-environments
[gitlab-deploy-token]: ../../user/project/deploy_tokens/index.md#gitlab-deploy-token [gitlab-deploy-token]: ../../user/project/deploy_tokens/index.md#gitlab-deploy-token
[re2-library]: https://github.com/google/re2
[re2-syntax]: https://github.com/google/re2/wiki/Syntax

View file

@ -63,5 +63,18 @@ describe Gitlab::Ci::Pipeline::Expression::Lexeme::Matches do
expect(operator.evaluate).to eq true expect(operator.evaluate).to eq true
end end
it 'supports regexp flags' do
allow(left).to receive(:evaluate).and_return <<~TEXT
My AWESOME content
TEXT
allow(right).to receive(:evaluate)
.and_return(Gitlab::UntrustedRegexp.new('(?i)awesome'))
operator = described_class.new(left, right)
expect(operator.evaluate).to eq true
end
end end
end end

View file

@ -100,6 +100,7 @@ describe Gitlab::Ci::Pipeline::Expression::Statement do
"$PRESENT_VARIABLE =~ /^var.*/" | false "$PRESENT_VARIABLE =~ /^var.*/" | false
"$EMPTY_VARIABLE =~ /var.*/" | false "$EMPTY_VARIABLE =~ /var.*/" | false
"$UNDEFINED_VARIABLE =~ /var.*/" | false "$UNDEFINED_VARIABLE =~ /var.*/" | false
"$PRESENT_VARIABLE =~ /(?i)VAR.*/" | true
end end
with_them do with_them do