fix: split base file content on newline only when applying hunks - #69
Merged
Conversation
|
Warning Review limit reachedNext included review available in 58 minutes. View limit detailsLimit details: You’ve used the included review currently available. You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Review configuration: ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
vitali87
force-pushed
the
fix/apply-hunks-line-splitting
branch
from
August 30, 2026 13:06
7762aad to
f77512b
Compare
vitali87
force-pushed
the
fix/apply-hunks-line-splitting
branch
from
August 30, 2026 13:15
f77512b to
6dbe1ed
Compare
vitali87
force-pushed
the
fix/apply-hunks-line-splitting
branch
from
August 30, 2026 19:15
6dbe1ed to
3502459
Compare
vitali87
force-pushed
the
fix/apply-hunks-line-splitting
branch
from
August 30, 2026 19:16
3502459 to
2b24dae
Compare
apply_hunks used str.splitlines, which also breaks on form feed, vertical tab, \x1c-\x1e, \x85, \u2028 and \u2029. git counts none of those as line breaks, so a file containing one had every later hunk applied at the wrong offset: a line was lost and another duplicated, with no error. split_git_lines splits on \n only, matching git's line numbering.
vitali87
force-pushed
the
fix/apply-hunks-line-splitting
branch
from
August 30, 2026 19:17
2b24dae to
ab692d4
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
apply_hunkssplit the base file withstr.splitlines(keepends=True), which treats\x0c(form feed),\x0b,\x1c–\x1e,\x85,andas line breaks. git does not, so hunksource_startoffsets refer to\n-counted lines while the slice was applied to a differently-numbered list. Any file containing one of those characters before a hunk (form feeds are common in older Python/C sources and Emacs page breaks) is silently corrupted in every sub-PR:Fix
split_git_lines(content)splits on\nonly (keeping the terminator, handling a missing trailing newline and empty content), andapply_hunksuses it.Tests
split_git_linesparametrised over empty / trailing-newline-less / form feed / vertical tab / U+2028 / NEL / CRLF / blank linesapply_hunksregression with a form feed on line 1 and a hunk at line 7 reconstructs the dev content exactly458 tests pass, ruff clean.
Stacked on #50 (
fix/preserve-missing-trailing-newline) because both editapply_hunks; retargetsmainwhen #50 merges.