Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PCRE RegEx broken #932

Open
djettah opened this issue Jul 12, 2023 · 4 comments · May be fixed by #935
Open

PCRE RegEx broken #932

djettah opened this issue Jul 12, 2023 · 4 comments · May be fixed by #935
Labels
bug Something isn't working

Comments

@djettah
Copy link

djettah commented Jul 12, 2023

Minimal .gitlab-ci.yml illustrating the issue

build-fake:
  stage: build
  variables:
    REGEX: '/^(\d+(\.\d+)*|latest)$/'
  script:
    - echo fake build
  rules:
    - if: $CI_COMMIT_TAG =~ $REGEX

Expected behavior
It should match a job but it doesn't:

# gitlab-ci-local --list --variable CI_COMMIT_TAG=1.11  
parsing and downloads finished in 56 ms
name        description  stage   when   allow_failure  needs

# gitlab-ci-local --list --variable CI_COMMIT_TAG=latest
parsing and downloads finished in 80 ms
name        description  stage   when        allow_failure  needs
build-fake               build   on_success  false      

Doesn't it support PCRE? GitLab does.

Host information
Ubuntu
gitlab-ci-local 4.41.2

Additional context
Add any other context about the problem here.

@firecow
Copy link
Owner

firecow commented Jul 14, 2023

We must support PCRE, but i don't think we do at the moment 👍

image

Something is definitely wrong 😃

@firecow firecow added the bug Something isn't working label Jul 14, 2023
@firecow firecow linked a pull request Jul 14, 2023 that will close this issue
@naweiss
Copy link
Collaborator

naweiss commented Jul 27, 2023

@firecow
Copy link
Owner

firecow commented Jul 27, 2023

Great, we need to utilize this package if possible then.
https://www.npmjs.com/package/re2

@naweiss
Copy link
Collaborator

naweiss commented Jul 27, 2023

@firecow I wish I would understood your first comment earlier. After digging into this subject for 3 hours I found out that the image you posted clearly shows that the specific regex mentioned in this issue should work using RegExp without the need for RE2 or PCRE . gitlab-ci-local handles the following case perfectly fine:

build-fake:
  stage: build
  script:
    - echo fake build
  rules:
    - if: $CI_COMMIT_TAG =~ /^(\d+(\.\d+)*|latest)$/

To be clear, yes we should support RE2 to allow things like '/^([[:digit:]]+(\.[[:digit:]]+)*|latest)$/' which are not supported by JS RegExp. But, there is another bug that causes the mentioned REGEX expansion to fail:

variable: (name) => JSON.stringify(envs[name] ?? null),

since REGEX is a variable it is replaced with JSON.stringify(envs[name]) which replaces every \ with \\. So, the evaluated result becomes: "1.11".match(/^(\\d+(\.\\d+)*|latest)$/) != null instead of "1.11".match(/^(\d+(\.\d+)*|latest)$/) != null.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants