Read quoted and " b/"-containing paths in Patch() headers - #129
Merged
Merged
Conversation
The diff --git header was split at the last " b/", so a path such as "Plan b/notes.txt" came back as "notes.txt", and a header whose paths git had C-quoted threw GitParseException for the whole patch. Headers without a rename are now split at the midpoint, as git's own git_header_name does, and quoted operands and rename from/to lines are decoded, octal escapes included. Fixes #120 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01VKxYoUXQqgRKJR6ynbvnms
RelativeFilePath normalizes separators, so on Windows the parsed "Plan b/notes.txt" reads back as "Plan b\notes.txt". Compare against the same value built as a RelativeFilePath, as the builder tests do. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01VKxYoUXQqgRKJR6ynbvnms
UnquotePath is now internal so its escape table can be tested directly; most escapes decode to control characters that RelativeFilePath refuses on Windows, so they cannot go through a parsed header. Adds header cases for one side quoted and the other not, and for malformed quoting. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01VKxYoUXQqgRKJR6ynbvnms
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01VKxYoUXQqgRKJR6ynbvnms
|
This was referenced Sep 27, 2026
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.



Fixes #120
What changed
GitPatchParser.ReadPathFromFileStartfound the new-side path by taking whatever followed the last" b/"in the header. That broke in two cases:b/.Plan b/notes.txtcame back asnotes.txt.",\or a control character even withcore.quotepath=false. That header has nob/, soPatch()threwGitParseExceptionfor the whole repository.The parser now reads the header this way:
a/P b/Pat the midpoint and checks that the halves match. Git's owngit_header_namedoes the same.\",\\,\t,\nand the others, plus octal\NNNbytes read as UTF-8. Therename from/rename tolines are decoded the same way, and so is thediff --ccpath." b/"search. That is only a placeholder, because therename toline replaces it, as before.Tests
patch-b-slash-in-path.txt,patch-quoted-path.txtandpatch-quoted-rename.txt.Plan b/notes.txt,say "hi".txt, a quoted rename, an octal UTF-8 escape, and a quoted file followed by an ordinary one in the same patch. The last one checks that one quoted name no longer breaks the rest.RelativeFilePathvalidation rejects control characters, so tab-named fixtures would fail there.With the parser change reverted, all 5 new tests fail. With it, the full suite passes: 713 tests, 0 failed.
🤖 Generated with Claude Code
https://claude.ai/code/session_01VKxYoUXQqgRKJR6ynbvnms
Generated by Claude Code