[PR #13106] fix(edit): unescape newString replacements to avoid literal \\n #14513

Open
opened 2026-02-16 18:19:18 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/anomalyco/opencode/pull/13106

State: open
Merged: No


What does this PR do?

Fixes #3545.

edit currently unescapes matching for oldString but writes newString directly. Some providers send newString with escaped \\n, which can cause literal \n to be written to files.

Changes:

  • move unescapeString to a shared helper in packages/opencode/src/tool/edit.ts
  • apply unescape to replacement text in replace(...)
  • apply unescape in the oldString === "" write path
  • add regression tests in packages/opencode/test/tool/edit.test.ts

How did you verify your code works?

  • Added regression tests for:
    • escaped newline replacement
    • replaceAll path
    • double-escaped \\\\n remaining literal when intended
  • GitHub Actions passed on this PR:
    • typecheck
    • unit (linux)
    • e2e (linux)
    • e2e (windows)
    • test (linux)
**Original Pull Request:** https://github.com/anomalyco/opencode/pull/13106 **State:** open **Merged:** No --- ### What does this PR do? Fixes #3545. `edit` currently unescapes matching for `oldString` but writes `newString` directly. Some providers send `newString` with escaped `\\n`, which can cause literal `\n` to be written to files. Changes: - move `unescapeString` to a shared helper in `packages/opencode/src/tool/edit.ts` - apply unescape to replacement text in `replace(...)` - apply unescape in the `oldString === ""` write path - add regression tests in `packages/opencode/test/tool/edit.test.ts` ### How did you verify your code works? - Added regression tests for: - escaped newline replacement - `replaceAll` path - double-escaped `\\\\n` remaining literal when intended - GitHub Actions passed on this PR: - `typecheck` - `unit (linux)` - `e2e (linux)` - `e2e (windows)` - `test (linux)`
yindo added the pull-request label 2026-02-16 18:19:18 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#14513