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

[BUG] Bad JSON escape sequence #2350

Closed
4 tasks done
TimatGDC opened this issue Nov 18, 2024 · 3 comments
Closed
4 tasks done

[BUG] Bad JSON escape sequence #2350

TimatGDC opened this issue Nov 18, 2024 · 3 comments
Labels
bug Something isn't working

Comments

@TimatGDC
Copy link

TimatGDC commented Nov 18, 2024

Is there an existing issue for this?

  • I have searched the existing issues

Does this issue exist in the latest version?

  • I'm using the latest release

Describe the bug?

I was trying to run the workflow using your matrix example:

name: 🕵️ Detect Credentials on PR

on:
  pull_request:

jobs:
  changed-files:
    name: Get changed files
    runs-on: ubuntu-24.04
    outputs:
      matrix: ${{ steps.changed-files.outputs.all_changed_files }}
    steps:
      - name: Checkout
        uses: actions/checkout@v4
        with:
          fetch-depth: 0
      - name: Get changed files
        id: changed-files
        uses: tj-actions/changed-files@v45
        with:
          matrix: true
          since_last_remote_commit: true
      - name: List all changed files
        run: echo '${{ steps.changed-files.outputs.all_changed_files }}'

  matrix-job:
    name: Run Matrix Job
    runs-on: ubuntu-24.04
    needs: [changed-files]
    strategy:
      matrix: 
        files: ${{ fromJSON(needs.changed-files.outputs.matrix) }}
      max-parallel: 4
      fail-fast: false
    steps:
      - name: Checkout
        uses: actions/checkout@v4
      - name: Test
        run: |
          echo ${{ matrix.files }}

The goal is to list only the changed file in this PR.

My team uses Next.js, and as a convention, it generate folder with parenthesis. See here. But, when i test it, i ran into an issue:
Bad JSON escape sequence

To Reproduce

  1. Create a folder with parenthesis, for example (auth)
  2. Create a file inside that folder, write on it and push it to activate the workflow
  3. There will be a Bad JSON escape sequence error due to the escaped parenthesis in the path of the folder

What OS are you seeing the problem on?

ubuntu-24.04

Expected behavior?

In the list of changed files:

[".github/workflows/\(folder\)/testfile.txt",".github/workflows/other-test-file.txt",".github/workflows/plateform-auto-detect-credential-pr.yml"]

.github/workflows/\(folder\)/testfile.txt" should be .github/workflows/(folder)/testfile.txt"

Relevant log output

# Log for "List All Changed Files"

[".github/workflows/\(folder\)/testfile.txt",".github/workflows/other-test-file.txt",".github/workflows/plateform-auto-detect-credential-pr.yml"]

# Error For Matrix Job

Error when evaluating 'strategy' for job 'matrix-job'. .github/workflows/plateform-auto-detect-credential-pr.yml (Line: 31, Col: 16): Error parsing fromJson,.github/workflows/plateform-auto-detect-credential-pr.yml (Line: 31, Col: 16): Bad JSON escape sequence: \(. Path '', line 1, position 22.,.github/workflows/plateform-auto-detect-credential-pr.yml (Line: 31, Col: 16): Unexpected value ''

Has all relevant logs been included?

  • I've included all relevant logs

Anything else?

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct
@TimatGDC TimatGDC added the bug Something isn't working label Nov 18, 2024
@tj-actions-bot
Copy link
Contributor

Thanks for reporting this issue, don't forget to star this project if you haven't already to help us reach a wider audience.

@jackton1
Copy link
Member

jackton1 commented Nov 18, 2024

Hi @TimatGDC, if you use parenthesis () in the folder name, you would need to set safe_output to false to prevent unsafe shell characters from being escaped.

@jackton1 jackton1 closed this as not planned Won't fix, can't repro, duplicate, stale Nov 18, 2024
@TimatGDC
Copy link
Author

Oh you're right, did not see that one. I was searching for "escaping" in the doc, and not "sanitize", my bad 😅 . Thanks for the help

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

No branches or pull requests

3 participants