Fix sed substitution of {{TOPIC}} mangling/breaking on special chars#5
Open
skytow wants to merge 1 commit into
Open
Fix sed substitution of {{TOPIC}} mangling/breaking on special chars#5skytow wants to merge 1 commit into
skytow wants to merge 1 commit into
Conversation
start-loop.sh injected the user-provided topic into the plan-mode prompt
templates via `sed "s|{{TOPIC}}|$TOPIC|g"`. In a sed replacement three
characters are special: `&` (the whole matched text, i.e. `{{TOPIC}}`),
the `|` delimiter, and `\`. So a topic like "Paywall & monetization"
rendered as "Paywall {{TOPIC}} monetization", and a topic containing `|`
crashed sed outright ("bad flag in substitute command").
Escape `\`, `&`, and `|` (and collapse newlines, since sed is
line-oriented) into SED_SAFE_TOPIC before substitution. REVIEW_ID and
MAX_ROUNDS are a generated id and an integer, so they need no escaping.
Verified: a topic with `& | \` now round-trips verbatim; bash -n passes;
doctor + smoke test (74/74) still green. stop-hook.sh is unaffected (it
expands $TOPIC via bash, not sed).
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.
Problem
plugins/claudex/scripts/start-loop.shinjects the user-provided topic into the plan-mode prompt templates with:sed -e "s|{{TOPIC}}|$TOPIC|g" ...In a sed replacement, three characters are special:
&— expands to the whole matched text ({{TOPIC}})|— the substitution delimiter\— escape charSo a topic like
add expiry & cleanuprenders asadd expiry {{TOPIC}} cleanup, and a topic containing|(e.g. an interview-enriched topic) crashes sed withbad flag in substitute command.Repro:
Fix
Escape
\,&, and|(and collapse newlines, since sed is line-oriented) into aSED_SAFE_TOPICbefore substitution, and use it in bothsedcalls.REVIEW_ID(generated id) andMAX_ROUNDS(integer) can't contain special chars, so they're left as-is.SED_SAFE_TOPIC="$(printf '%s' "$TOPIC" | tr '\n\r' ' ' | sed -e 's/[\\&|]/\\&/g')"Verification
& | \now round-trips verbatim.bash -npasses;doctor.shhealthy; smoke test 74/74 still green.stop-hook.shis unaffected — it expands$TOPICvia bash, not sed (so the actual Codex review prompts were always correct; only the round-1 drafting instructions were cosmetically mangled).🤖 Generated with Claude Code