Skip to content

fix(core): match LF regions of mixed-ending files in edit - #45888

Open
skyzhao1223 wants to merge 1 commit into
anomalyco:devfrom
skyzhao1223:fix/edit-mixed-line-endings
Open

skyzhao1223 wants to merge 1 commit into
anomalyco:devfrom
skyzhao1223:fix/edit-mixed-line-endings

Conversation

@skyzhao1223

Copy link
Copy Markdown
Contributor

Issue for this PR

Closes #45880

Type of change

  • Bug fix

What does this PR do?

The read tool strips a trailing \r from each line, so the model always sees pure LF content. But detectLineEnding in the edit tool classified any file containing a single CRLF as a CRLF file, and then rewrote the model's entire oldString to CRLF. On a file with mixed endings (one commit from a Windows colleague is enough), oldStrings targeting LF regions could never match and the edit failed with a misleading "Could not find oldString".

This is the conservative first step discussed in the issue: treat a file as CRLF only when every newline is a CRLF. Consistently CRLF files behave exactly as before (covered by the existing "preserves BOM and CRLF line endings" test). Mixed-ending files now match as LF, so their LF regions become editable, and untouched CRLF lines keep their original endings byte-for-byte.

Known limitation left open in #45880: editing the CRLF region of a mixed file still won't match. Fixing that properly needs a policy decision (preserve mixed endings vs. normalize to the dominant ending) plus normalized-search span mapping, so I kept it out of this PR.

How did you verify your code works?

New test: editing the LF region of alpha\nbeta\r\ngamma\n succeeds and leaves the CRLF line untouched (ALPHA\r\ngamma\n). bun test ./test/tool-edit.test.ts ./test/tool-write.test.ts: 18 pass. bun run typecheck clean, prettier clean.

Screenshots / recordings

Not a UI change.

Checklist

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

detectLineEnding treated any file containing a single CRLF as a CRLF
file and rewrote the model's oldString to CRLF wholesale. The read tool
strips trailing \r, so on mixed-ending files the model reproduced pure
LF content that the edit path could then never match, failing with a
misleading "Could not find oldString".

Treat a file as CRLF only when every newline is a CRLF. Consistent CRLF
files behave exactly as before; mixed files match as LF, so LF regions
become editable and untouched CRLF lines keep their original endings.
Editing the CRLF region of a mixed file still requires follow-up work
tracked in anomalyco#45880.

Fixes anomalyco#45880
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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)

1 participant