summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGrzegorz Bizon <grzesiek.bizon@gmail.com>2018-05-15 15:18:18 +0200
committerGrzegorz Bizon <grzesiek.bizon@gmail.com>2018-05-15 15:18:18 +0200
commitf52de2f73cc9d26c26fd66c23892ac42bf973b05 (patch)
treefde78876e6526ba3cea0f33cf33500ff9ad255d6
parent73aee958e2f4f7428a961c3c63323a7b782599bf (diff)
downloadgitlab-ce-f52de2f73cc9d26c26fd66c23892ac42bf973b05.tar.gz
Make variables expression pattern case-sensitivity explicit
-rw-r--r--doc/ci/variables/README.md8
-rw-r--r--spec/lib/gitlab/ci/pipeline/expression/lexeme/matches_spec.rb13
-rw-r--r--spec/lib/gitlab/ci/pipeline/expression/statement_spec.rb1
3 files changed, 22 insertions, 0 deletions
diff --git a/doc/ci/variables/README.md b/doc/ci/variables/README.md
index cbd2ab979f4..58acc030aee 100644
--- a/doc/ci/variables/README.md
+++ b/doc/ci/variables/README.md
@@ -537,6 +537,12 @@ Below you can find supported syntax reference:
It is possible perform pattern matching against a variable and regular
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
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
[dynamic-environments]: ../environments.md#dynamic-environments
[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
diff --git a/spec/lib/gitlab/ci/pipeline/expression/lexeme/matches_spec.rb b/spec/lib/gitlab/ci/pipeline/expression/lexeme/matches_spec.rb
index a8890262402..49e5af52f4d 100644
--- a/spec/lib/gitlab/ci/pipeline/expression/lexeme/matches_spec.rb
+++ b/spec/lib/gitlab/ci/pipeline/expression/lexeme/matches_spec.rb
@@ -63,5 +63,18 @@ describe Gitlab::Ci::Pipeline::Expression::Lexeme::Matches do
expect(operator.evaluate).to eq true
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
diff --git a/spec/lib/gitlab/ci/pipeline/expression/statement_spec.rb b/spec/lib/gitlab/ci/pipeline/expression/statement_spec.rb
index bba5db7904a..1ceb373e19c 100644
--- a/spec/lib/gitlab/ci/pipeline/expression/statement_spec.rb
+++ b/spec/lib/gitlab/ci/pipeline/expression/statement_spec.rb
@@ -100,6 +100,7 @@ describe Gitlab::Ci::Pipeline::Expression::Statement do
"$PRESENT_VARIABLE =~ /^var.*/" | false
"$EMPTY_VARIABLE =~ /var.*/" | false
"$UNDEFINED_VARIABLE =~ /var.*/" | false
+ "$PRESENT_VARIABLE =~ /(?i)VAR.*/" | true
end
with_them do