Allow empty string matching in RegEx

What does this MR do and why?

Fixes match? method of the ::Gitlab::UntrustedRegexp ... (#477707 - closed)

The match? method immediately rejects empty strings even if the regular expression itself would allow matching the empty string.

Due to how widely the method is used throughout the entire project, this behavior might be relied on in many places. This commit introduces a new parameter to explicitly allow matching empty strings when desired.

References

How to set up and validate locally

  1. Create new project with the following two files:

    component.yml:

    spec:
      inputs:
        myinput:
          default: ""
          regex: \w{0,2}
    ---
    job:
      script:
        - echo my value is "$[[ inputs.myinput ]]"

    .gitlab-ci.yml:

    include:
      - local: component.yml
  2. Run a new pipeline

  3. Observe default value does not match required RegEx pattern error when using current code

  4. Observe pipeline getting created when using this branch

  5. [Optional] Change default: "" to default: "test" in component.yml and observe pipeline getting created when using current code with no error message to see the difference in behavior – both the empty string and test match the \w{0,2} RegEx, but the empty string causes a problem.

Edited by Manuel Grabowski

Merge request reports

Loading