Fix JSON escaping with jq#795
Open
mendral-app[bot] wants to merge 1 commit into
Open
Conversation
The 'Prepare error message' step used ${{ env.TEST_OUTPUT }} interpolation
directly in the shell script, causing bash to interpret special characters
(backticks, quotes, path-like strings) in Python tracebacks. The sed-based
escaping was insufficient because the string was already broken at the shell
expansion level.
Fix:
- Pass TEST_OUTPUT via env: block (as RAW_OUTPUT) to avoid shell interpretation
- Use jq -Rs for proper JSON string escaping of all special characters
- Add head -c 3000 to truncate very long tracebacks
- Strip outer quotes from jq output for embedding in JSON string
|
PR author is not in the allowed authors list. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
sed-based escaping in the Slack notification step withjq -Rsfor proper JSON string encoding that handles all special characters (quotes, backticks, backslashes, path-like strings)TEST_OUTPUTviaenv:block instead of${{ }}interpolation to prevent bash from interpreting special characters before escaping can occurProblem
The "Prepare error message" step in
nightly-test-releasefails when test output contains Python tracebacks with shell-special characters. The${{ env.TEST_OUTPUT }}expression is expanded by GitHub Actions before the shell runs, injecting raw traceback text directly into the script. Characters like backticks, unmatched quotes, and path-like strings (sessions/start) are interpreted by bash, producing errors likeline 52: sessions/start: No such file or directoryand ultimately an invalid JSON payload for Slack.Fix
TEST_OUTPUTviaenv:block (asRAW_OUTPUT) — prevents shell interpretationjq -Rs .for proper JSON string escaping of all special charactershead -c 3000to truncate very long tracebacks that could exceed GitHub output limitsRelated
Note
Created by Mendral. Tag @mendral-app with feedback or questions.