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

backslash then double slash within double quotes throws syntax error #1335

Closed
tan-wei-xin-alez opened this issue Sep 11, 2024 · 2 comments · Fixed by #1340
Closed

backslash then double slash within double quotes throws syntax error #1335

tan-wei-xin-alez opened this issue Sep 11, 2024 · 2 comments · Fixed by #1340
Labels
bug Something isn't working

Comments

@tan-wei-xin-alez
Copy link

Minimal .gitlab-ci.yml illustrating the issue

---

stages:
  - test

test-job:
  stage: test
  image: public.ecr.aws/docker/library/python:latest
  tags:
    - <runner_tag>
  rules:
    - if: $TEST_URL =~ $REGEX_VAR
  variables:
    TEST_URL: "test/url"
    REGEX_VAR: "/test\//"
  script:
    - echo 'test'

The above throws the following syntax error when trying to use --preview or running the job itself

➜  ~ rm -rf <project_dir>/.gitlab-ci-local && gitlab-ci-local --cwd <project_dir> --preview
Using fallback git commit data
Unable to retrieve default remote branch, falling back to `main`.
Using fallback git remote data
SyntaxError: Unexpected token ')'
    at Function.evaluateRuleIf (/home/linuxbrew/.linuxbrew/Cellar/gitlab-ci-local/4.53.0/libexec/lib/node_modules/gitlab-ci-local/src/utils.ts:221:29)
    at Function.getRulesResult (/home/linuxbrew/.linuxbrew/Cellar/gitlab-ci-local/4.53.0/libexec/lib/node_modules/gitlab-ci-local/src/utils.ts:185:24)
    at new Job (/home/linuxbrew/.linuxbrew/Cellar/gitlab-ci-local/4.53.0/libexec/lib/node_modules/gitlab-ci-local/src/job.ts:216:38)
    at /home/linuxbrew/.linuxbrew/Cellar/gitlab-ci-local/4.53.0/libexec/lib/node_modules/gitlab-ci-local/src/parser.ts:176:29
    at Function.forEachRealJob (/home/linuxbrew/.linuxbrew/Cellar/gitlab-ci-local/4.53.0/libexec/lib/node_modules/gitlab-ci-local/src/utils.ts:54:13)
    at Parser.init (/home/linuxbrew/.linuxbrew/Cellar/gitlab-ci-local/4.53.0/libexec/lib/node_modules/gitlab-ci-local/src/parser.ts:162:15)
    at Function.create (/home/linuxbrew/.linuxbrew/Cellar/gitlab-ci-local/4.53.0/libexec/lib/node_modules/gitlab-ci-local/src/parser.ts:60:9)
    at handler (/home/linuxbrew/.linuxbrew/Cellar/gitlab-ci-local/4.53.0/libexec/lib/node_modules/gitlab-ci-local/src/handler.ts:45:18)
    at Object.handler (/home/linuxbrew/.linuxbrew/Cellar/gitlab-ci-local/4.53.0/libexec/lib/node_modules/gitlab-ci-local/src/index.ts:37:21)

➜  ~ rm -rf <project_dir>/.gitlab-ci-local && gitlab-ci-local --cwd <project_dir> test-job
Using fallback git commit data
Unable to retrieve default remote branch, falling back to `main`.
Using fallback git remote data
SyntaxError: Unexpected token ')'
    at Function.evaluateRuleIf (/home/linuxbrew/.linuxbrew/Cellar/gitlab-ci-local/4.53.0/libexec/lib/node_modules/gitlab-ci-local/src/utils.ts:221:29)
    at Function.getRulesResult (/home/linuxbrew/.linuxbrew/Cellar/gitlab-ci-local/4.53.0/libexec/lib/node_modules/gitlab-ci-local/src/utils.ts:185:24)
    at new Job (/home/linuxbrew/.linuxbrew/Cellar/gitlab-ci-local/4.53.0/libexec/lib/node_modules/gitlab-ci-local/src/job.ts:216:38)
    at /home/linuxbrew/.linuxbrew/Cellar/gitlab-ci-local/4.53.0/libexec/lib/node_modules/gitlab-ci-local/src/parser.ts:176:29
    at Function.forEachRealJob (/home/linuxbrew/.linuxbrew/Cellar/gitlab-ci-local/4.53.0/libexec/lib/node_modules/gitlab-ci-local/src/utils.ts:54:13)
    at Parser.init (/home/linuxbrew/.linuxbrew/Cellar/gitlab-ci-local/4.53.0/libexec/lib/node_modules/gitlab-ci-local/src/parser.ts:162:15)
    at Function.create (/home/linuxbrew/.linuxbrew/Cellar/gitlab-ci-local/4.53.0/libexec/lib/node_modules/gitlab-ci-local/src/parser.ts:60:9)
    at handler (/home/linuxbrew/.linuxbrew/Cellar/gitlab-ci-local/4.53.0/libexec/lib/node_modules/gitlab-ci-local/src/handler.ts:78:18)
    at Object.handler (/home/linuxbrew/.linuxbrew/Cellar/gitlab-ci-local/4.53.0/libexec/lib/node_modules/gitlab-ci-local/src/index.ts:37:21)

Expected behavior
image

Host information

➜  ~ fastfetch
                            ....               
              .',:clooo:  .:looooo:.           ------------------------
           .;looooooooc  .oooooooooo'          OS: Ubuntu focal 20.04 x86_64
        .;looooool:,''.  :ooooooooooc          Host: Precision 5570
       ;looool;.         'oooooooooo,          Kernel: 5.15.0-88-generic
      ;clool'             .cooooooc.  ,,       Uptime: 26 days, 23 hours, 27 mins
         ...                ......  .:oo,      Packages: 2267 (dpkg), 15 (snap), 206 (brew)
  .;clol:,.                        .loooo'     Shell: zsh 5.9
 :ooooooooo,                        'ooool     Display (LG HDR 4K): 3840x2160 @ 60Hz *
'ooooooooooo.                        loooo.    Display (SHP1515): 1920x1200 @ 60Hz
'ooooooooool                         coooo.    Display (ARZOPA): 1920x1080 @ 30Hz
 ,loooooooc.                        .loooo.    Display (SyncMaster): 1920x1200 @ 60Hz
   .,;;;'.                          ;ooooc     DE: Gnome 3.36.9
       ...                         ,ooool.     WM: Mutter (X11)
    .cooooc.              ..',,'.  .cooo.      WM Theme: Yaru
      ;ooooo:.           ;oooooooc.  :l.       Theme: Yaru [GTK2/3/4]
       .coooooc,..      coooooooooo.           Icons: Yaru [GTK2/3/4]
         .:ooooooolc:. .ooooooooooo'           Font: Ubuntu (11pt) [GTK2/3/4]
           .':loooooo;  ,oooooooooc            Cursor: Yaru (24px)
               ..';::c'  .;loooo:'             Terminal: tmux 3.4
                             .                 CPU: 12th Gen Intel(R) Core(TM) i9-12900H (20) @ 5.00 GHz
                                               GPU 1: NVIDIA Device 25BA (3D)
                                               GPU 2: Intel Device 46A6 (VGA compatible)
                                               Memory: 23.41 GiB / 62.47 GiB (37%)
                                               Swap: 1.98 GiB / 2.00 GiB (99%)
                                               Disk (/): 358.88 GiB / 929.04 GiB (39%) - ext4
                                               Local IP (enx349971e7b9cf): 192.168.178.48/24 *
                                               Battery: 100% [AC Connected]
                                               Locale: en_US.UTF-8

➜  ~ gitlab-ci-local --version
4.53.0

Containerd binary

➜  ~ docker version
Client: Docker Engine - Community
 Version:           27.2.1
 API version:       1.47
 Go version:        go1.22.7
 Git commit:        9e34c9b
 Built:             Fri Sep  6 12:08:15 2024
 OS/Arch:           linux/amd64
 Context:           default

Server: Docker Engine - Community
 Engine:
  Version:          27.2.1
  API version:      1.47 (minimum version 1.24)
  Go version:       go1.22.7
  Git commit:       8b539b8
  Built:            Fri Sep  6 12:08:15 2024
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.7.21
  GitCommit:        472731909fa34bd7bc9c087e4c27943f9835f111
 nvidia:
  Version:          1.1.13
  GitCommit:        v1.1.13-0-g58aa920
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0

Additional context
Changing REGEX_VAR: "/test\//" to REGEX_VAR: '/test\//' seems to get around the issue although it seems strange that the backslash would not be interpreted literally in that case, also works with REGEX_VAR: "/test\/" but I believe that's not the same thing?

Using REGEX_VAR: '/test\/', on the other hand, throws a different syntax error

➜  ~ rm -rf <project_dir>/.gitlab-ci-local && gitlab-ci-local --cwd <project_dir> test-job
Using fallback git commit data
Unable to retrieve default remote branch, falling back to `main`.
Using fallback git remote data
SyntaxError: Invalid regular expression: missing /
    at Function.evaluateRuleIf (/home/linuxbrew/.linuxbrew/Cellar/gitlab-ci-local/4.53.0/libexec/lib/node_modules/gitlab-ci-local/src/utils.ts:221:29)
    at Function.getRulesResult (/home/linuxbrew/.linuxbrew/Cellar/gitlab-ci-local/4.53.0/libexec/lib/node_modules/gitlab-ci-local/src/utils.ts:185:24)
    at new Job (/home/linuxbrew/.linuxbrew/Cellar/gitlab-ci-local/4.53.0/libexec/lib/node_modules/gitlab-ci-local/src/job.ts:216:38)
    at /home/linuxbrew/.linuxbrew/Cellar/gitlab-ci-local/4.53.0/libexec/lib/node_modules/gitlab-ci-local/src/parser.ts:176:29
    at Function.forEachRealJob (/home/linuxbrew/.linuxbrew/Cellar/gitlab-ci-local/4.53.0/libexec/lib/node_modules/gitlab-ci-local/src/utils.ts:54:13)
    at Parser.init (/home/linuxbrew/.linuxbrew/Cellar/gitlab-ci-local/4.53.0/libexec/lib/node_modules/gitlab-ci-local/src/parser.ts:162:15)
    at Function.create (/home/linuxbrew/.linuxbrew/Cellar/gitlab-ci-local/4.53.0/libexec/lib/node_modules/gitlab-ci-local/src/parser.ts:60:9)
    at handler (/home/linuxbrew/.linuxbrew/Cellar/gitlab-ci-local/4.53.0/libexec/lib/node_modules/gitlab-ci-local/src/handler.ts:45:18)
    at Object.handler (/home/linuxbrew/.linuxbrew/Cellar/gitlab-ci-local/4.53.0/libexec/lib/node_modules/gitlab-ci-local/src/index.ts:37:21)

I don't know if the above is specific to gitlab's kubernetes executor but if it is, feel free to close this issue and link it to #1064

@ANGkeith
Copy link
Collaborator

ANGkeith commented Sep 12, 2024

I don't know if the above is specific to gitlab's [kubernetes executor]

nope, doesnt seemed like it

@ANGkeith ANGkeith added the bug Something isn't working label Sep 12, 2024
@ANGkeith
Copy link
Collaborator

ANGkeith commented Sep 12, 2024

For now, change to either of the following should work similar in gitlab.com and gcl:

variables:
    REGEX_VAR: /test\//
    REGEX_VAR: '/test\//'
    
     # NOTE: we are using double the backslash `\\`!  this is due to how the yaml parsers parses double quoted string and the edge case that's not handled on our side
    REGEX_VAR: "/test\\//"

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.

2 participants