Skip to content

fix(edit): match LF regions of mixed-ending files - #53253

Closed
ggbdpq wants to merge 1 commit into
anomalyco:devfrom
ggbdpq:fix/edit-mixed-ending-conservative-match
Closed

ggbdpq wants to merge 1 commit into
anomalyco:devfrom
ggbdpq:fix/edit-mixed-ending-conservative-match

Conversation

@ggbdpq

@ggbdpq ggbdpq commented Oct 5, 2026 •

Copy link
Copy Markdown

Issue for this PR

Closes #45880

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

detectLineEnding picked CRLF as soon as the file contained a single \r\n, and everything in oldString/newString got rewritten to CRLF. In a mixed-ending file that converted oldString no longer exists — the model can only ever produce LF strings, because read strips \r before showing content. Worse, when the fallback matcher still located the region, the replacement landed with CRLF endings inside an LF area, silently corrupting those lines.

The fix: a file only detects as CRLF when every newline in it is CRLF, so mixed files match as LF — consistent with the LF view read shows. Fully-CRLF and LF-only files behave exactly as before.

This is the conservative first step discussed in the issue. Editing the CRLF region of a mixed file still has open policy questions (preserve the file byte-for-byte vs normalize the touched region) that need a maintainer decision, so I left that out.

How did you verify your code works?

Added matches LF regions of a mixed-ending file to packages/opencode/test/tool/edit.test.ts. Before the fix the file came back with a stray \r\n injected into the LF region (alpha\r\nbeta-updated\ngamma\n instead of alpha\nbeta-updated\ngamma\n); after the fix the LF region is edited and the CRLF line stays byte-identical.

Full packages/opencode/test/tool/ suite: 342 pass / 0 fail (edit.test.ts is 30/30, including every existing CRLF-preservation case). tsgo --noEmit in packages/opencode is clean.

Screenshots / recordings

Not a UI change.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

@github-actions github-actions Bot added the needs:compliance This means the issue will auto-close after 2 hours. label Oct 5, 2026
@github-actions

github-actions Bot commented Oct 5, 2026

Copy link
Copy Markdown
Contributor

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

@github-actions github-actions Bot removed the needs:compliance This means the issue will auto-close after 2 hours. label Oct 5, 2026
@github-actions

github-actions Bot commented Oct 5, 2026

Copy link
Copy Markdown
Contributor

Thanks for updating your PR! It now meets our contributing guidelines. 👍

detectLineEnding flagged any file containing a single CRLF as a CRLF
file, so oldString/newString written with LF endings - which is all
the model can ever produce, since read strips \r - were rewritten to
CRLF. In mixed-ending files the converted oldString no longer matched,
and when the fallback matcher still found the region, the replacement
landed with wrong line endings, silently corrupting the touched area.

Detect CRLF only when every newline in the file is CRLF; mixed files
now match as LF, consistent with the LF view read shows the model.
Fully-CRLF and LF-only files behave exactly as before.

Closes #45880

Generated-by: GLM-5.3-Flash (ZCode)
@ggbdpq

ggbdpq commented Oct 9, 2026

Copy link
Copy Markdown
Author

Friendly ping — this has been open for a few days with green checks and no review feedback yet. Happy to rebase or adjust if anything needs changing. Thanks!

@thdxr

thdxr commented Oct 10, 2026

Copy link
Copy Markdown
Member

This branch has been upgraded to V2. We're no longer taking PRs for V1. If you think this is still relevant, please port it over and open it for V2.

— from 𝕺𝖕𝖊𝖓𝕮𝖔𝖉𝖊

@thdxr thdxr closed this Oct 10, 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.

edit: oldString never matches on files with mixed line endings (read strips \r, edit converts whole oldString to CRLF)

2 participants