Skip to content

fix(git-commit, git-copy): build API payloads with jq to escape JSON properly - #199

Open
VojtechVitek wants to merge 2 commits into
masterfrom
fix/git-commit-json-escaping
Open

fix(git-commit, git-copy): build API payloads with jq to escape JSON properly#199
VojtechVitek wants to merge 2 commits into
masterfrom
fix/git-commit-json-escaping

Conversation

@VojtechVitek

@VojtechVitek VojtechVitek commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

Problem

Both git-commit and git-copy build the pull-request creation payload by string interpolation and only escape newlines:

PR_DESCRIPTION_ESCAPED="${INPUT_PR_DESCRIPTION//$'\n'/\\n}"
--data "{\"head\":\"$INPUT_BRANCH\", ... \"body\": \"${PR_DESCRIPTION_ESCAPED}\"}"

Any double quote, backslash, or carriage return in pr_title / pr_description produces invalid JSON, the API returns 400/422, and PR creation fails. GitHub release notes use CRLF line endings, so passing a release body as pr_description always breaks (reproduced with the real webrpc/gen-golang v0.32.5 notes: jq: parse error: control characters from U+0000 through U+001F must be escaped).

Fix (applied identically to both actions)

  • Build the PR creation payload with jq -n --arg — correct escaping for all inputs, including the title.
  • Build the update_labels payload with jq instead of manual string concatenation. This also removes the IFS=',' assignment that leaked out of the function.
  • Fix a stray } in the update_labels curl credentials: -u "$INPUT_USER_NAME}:$API_TOKEN_GITHUB".

Also drops the ${var//...} bash-ism from #!/bin/sh scripts.

Testing

  • shellcheck -s sh and sh -n pass on both scripts (remaining warnings are pre-existing).
  • Payload round-trip tested with hostile input ("quotes", back\slash, CRLF): output is valid JSON and decodes byte-identical.

Motivation: webrpc/webrpc wants to include generator release notes in automated bump PR descriptions, which is impossible with the current escaping.

🤖 Generated with Claude Code

VojtechVitek and others added 2 commits July 30, 2026 15:49
The pull request payload was hand-built with string interpolation and
only escaped newlines. Any double quote, backslash, or carriage return
in pr_title/pr_description produced invalid JSON and the PR creation
silently failed. GitHub release notes use CRLF line endings, so passing
them as pr_description always broke.

- Build the PR creation payload with jq -n --arg (escapes everything)
- Build the labels payload with jq instead of manual concatenation
  (also drops the leaked IFS=',' assignment)
- Fix stray '}' in the update_labels curl credentials

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Same fixes as git-commit: the PR and labels payloads were hand-built
with string interpolation and broke on quotes, backslashes, or CRLF
in pr_title/pr_description/pr_labels.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@VojtechVitek VojtechVitek changed the title fix(git-commit): build API payloads with jq to escape JSON properly fix(git-commit, git-copy): build API payloads with jq to escape JSON properly Jul 30, 2026
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.

1 participant