Skip to content

Fix JSON escaping with jq#795

Open
mendral-app[bot] wants to merge 1 commit into
mainfrom
mendral/fix-slack-json-escaping
Open

Fix JSON escaping with jq#795
mendral-app[bot] wants to merge 1 commit into
mainfrom
mendral/fix-slack-json-escaping

Conversation

@mendral-app
Copy link
Copy Markdown

@mendral-app mendral-app Bot commented May 1, 2026

Summary

  • Replace fragile sed-based escaping in the Slack notification step with jq -Rs for proper JSON string encoding that handles all special characters (quotes, backticks, backslashes, path-like strings)
  • Pass TEST_OUTPUT via env: block instead of ${{ }} interpolation to prevent bash from interpreting special characters before escaping can occur

Problem

The "Prepare error message" step in nightly-test-release fails 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 like line 52: sessions/start: No such file or directory and ultimately an invalid JSON payload for Slack.

Fix

  1. Pass TEST_OUTPUT via env: block (as RAW_OUTPUT) — prevents shell interpretation
  2. Use jq -Rs . for proper JSON string escaping of all special characters
  3. Add head -c 3000 to truncate very long tracebacks that could exceed GitHub output limits
  4. Strip outer quotes from jq output for embedding inside the JSON string

Related


Note

Created by Mendral. Tag @mendral-app with feedback or questions.

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
@greptile-apps
Copy link
Copy Markdown

greptile-apps Bot commented May 1, 2026

PR author is not in the allowed authors list.

@mendral-app mendral-app Bot marked this pull request as ready for review May 1, 2026 16:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants