Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@openrouter/spawn",
"version": "1.0.35",
"version": "1.0.36",
"type": "module",
"bin": {
"spawn": "cli.js"
Expand Down
12 changes: 12 additions & 0 deletions packages/cli/src/__tests__/export.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,18 @@ describe("buildExportScript", () => {
expect(s).not.toContain("Possible secrets detected in staged files; aborting");
});

it("uses '#' as the sed delimiter — '|' would clash with SECRET_REGEX alternation", () => {
// Regression: the sed substitution previously used '|' as its delimiter
// ("s|${SECRET_REGEX}|${REDACT}|g"). Because SECRET_REGEX itself contains
// '|' (it's a |-separated alternation of provider patterns), bash
// expansion produced a string sed parsed with the wrong number of fields,
// failing with "unknown option to `s'". '#' is absent from both the regex
// and the placeholder, so the substitution is unambiguous.
const s = buildExportScript(opts);
expect(s).toContain('sed -i -E "s#${SECRET_REGEX}#${REDACT_PLACEHOLDER}#g"');
expect(s).not.toContain('sed -i -E "s|${SECRET_REGEX}|${REDACT_PLACEHOLDER}|g"');
});

it("pauses before commit with needs_confirmation when ALLOW_REDACT=0 (first pass)", () => {
const s = buildExportScript({
...opts,
Expand Down
6 changes: 5 additions & 1 deletion packages/cli/src/commands/export.ts
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,11 @@ export function buildExportScript(opts: {
' printf "%s\\n" "$SECRET_HITS" >&2',
" while IFS= read -r f; do",
' [ -z "$f" ] && continue',
' sed -i -E "s|${SECRET_REGEX}|${REDACT_PLACEHOLDER}|g" "$f"',
" # Delimiter is '#' — SECRET_REGEX contains '|' (alternation), so '|'",
" # as the sed delimiter would close the pattern at the first alternative",
" # (\"unknown option to s\"). '#' appears in neither the regex nor the",
" # placeholder, so the substitution is unambiguous.",
' sed -i -E "s#${SECRET_REGEX}#${REDACT_PLACEHOLDER}#g" "$f"',
' done <<< "$SECRET_HITS"',
" # Re-stage so the redacted blobs replace the originals in the index.",
" git add -A",
Expand Down
Loading