Skip to content

Conversation

@cnaples79
Copy link
Contributor

Summary

Patched files on Windows could end up with mixed CRLF/LF endings when applying Update File hunks. This change detects CRLF in the original file, normalizes lines for matching, and re-emits updated content using the original EOL style.

Rationale

Issue #4003 reports mixed EOLs after patch application on Windows. split/join used unconditionally, which produced LF for newly inserted lines even when the original file used CRLF.

Changes

  • Detect CRLF by checking for in original contents.
  • Strip trailing per line for diffing/matching.
  • Join updated lines with if original used CRLF; otherwise join with .
  • Add a test to ensure CRLF preservation on update.

Testing

  • New unit test writes a CRLF file, applies an update, and asserts CRLF-only output.
  • Existing tests pass locally in similar code paths; CI will validate full suite.

Fixes #4003

… files (Fixes openai#4003)

- Detect CRLF in original file, strip trailing \r for matching, and re-emit using original EOL style
- Add test to ensure updated files retain CRLF endings and avoid mixed EOLs
@github-actions
Copy link

github-actions bot commented Sep 21, 2025

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@cnaples79
Copy link
Contributor Author

I have read the CLA Document and I hereby sign the CLA

github-actions bot added a commit that referenced this pull request Sep 21, 2025
Copy link
Contributor

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Codex Review: Here are some suggestions.

About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you open a pull request for review, mark a draft as ready, or comment "@codex review". If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex fix this CI failure" or "@codex address that feedback".

…d unintended newline conversion\n\n- Count total vs CRLF pairs and treat as CRLF only if every newline is CRLF\n- Prevents converting LF-formatted files that contain embedded in literals
@etraut-openai
Copy link
Collaborator

Thanks for the contribution, and apologies for the slow reply. We received many PRs, and we're just now catching up on the backlog.

It looks like the PR has gone stale. If you're still interested in pursuing the PR, could you please resolve the merge conflicts? Thanks!

I haven't reviewed the change yet, but once it's in a good state, either I or one of my colleagues will review it.

@etraut-openai etraut-openai added the needs-response Additional information is requested label Nov 6, 2025
@cnaples79
Copy link
Contributor Author

@etraut-openai Ill resolve the merge conflicts and comment here once finished! Yes, still interested in this PR! That sounds good. Thank you.

youta7 added a commit to youta7/ta-codex that referenced this pull request Nov 10, 2025
@etraut-openai
Copy link
Collaborator

We received another PR that addresses this issue, so I'm going to close this one. Thanks again for taking the time to submit this PR.

@etraut-openai etraut-openai removed the needs-response Additional information is requested label Nov 12, 2025
@sharwell
Copy link

@etraut-openai I'd love to see this fixed 😄

@sharwell
Copy link

@cnaples79 In addition to mixed line endings, there is an interesting anomaly that occurs when using the VS Code extension, where a patch involving multiple files fails to show its content. Here's an example of a patch that involved a line ending change:

image

Here's an example of a patch that didn't change line endings:

image

Do you know if this pull request also fixes that issue?

@dylan-hurd-oai
Copy link
Collaborator

@cnaples79 as an FYI, I'm iterating on this PR in #7515 so that we can introduce this fix in a controlled manner. We appreciate your contribution here, and welcome thoughts on the other PR. You'll be credited for your work in the Release Notes once it is merged!

dylan-hurd-oai added a commit that referenced this pull request Dec 6, 2025
## Summary
This PR is heavily based on #4017, which contains the core logic for the
fix. To reduce the risk, we are first introducing it only on windows. We
can then expand to wsl / other environments as needed, and then tackle
net new files.

## Testing
- [x] added unit tests in apply-patch
- [x] add integration tests to apply_patch_cli.rs

---------

Co-authored-by: Chase Naples <[email protected]>
@etraut-openai
Copy link
Collaborator

@cnaples79 thanks again for the PR.

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.

Patched files have mixed line endings on Windows

4 participants