Skip to content

fix(edit): unescape newString replacements to avoid literal \\n#13106

Closed
webwww123 wants to merge 1 commit into
anomalyco:devfrom
webwww123:fix/edit-unescape-newstring-3545
Closed

fix(edit): unescape newString replacements to avoid literal \\n#13106
webwww123 wants to merge 1 commit into
anomalyco:devfrom
webwww123:fix/edit-unescape-newstring-3545

Conversation

@webwww123

@webwww123 webwww123 commented Feb 11, 2026

Copy link
Copy Markdown
Contributor

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)

@github-actions

Copy link
Copy Markdown
Contributor

The following comment was made by an LLM, it may be inaccurate:

No duplicate PRs found

@github-actions

Copy link
Copy Markdown
Contributor

Closing this pull request because it has had no updates for more than 60 days. If you plan to continue working on it, feel free to reopen or open a new PR.

@github-actions github-actions Bot closed this Apr 13, 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.

[Bug] LLMs editing python files not handling the newline character. Inserting \n instead of new line

1 participant