fix(patch): handle Windows drive-letter colons in patch header path parsing#13582
fix(patch): handle Windows drive-letter colons in patch header path parsing#13582machinekoder wants to merge 2 commits intoanomalyco:devfrom
Conversation
…arsing
parsePatchHeader used line.split(':', 2) to extract file paths from
headers like '*** Update File: D:\path\file.ts'. On Windows, the colon
in the drive letter (D:) caused split to truncate the path to just the
drive letter, producing invalid paths like 'D:\project\D'.
Replace split(':') with slice() after the known prefix length so the
full path including drive letter is preserved.
|
The following comment was made by an LLM, it may be inaccurate: Potential Related PR Found:
Note: The PR description acknowledges #10808 as a similar fix arrived at independently, so this is a known related PR rather than a true duplicate. |
There was a problem hiding this comment.
Pull request overview
This PR fixes Windows-specific path truncation in Patch.parsePatchHeader by avoiding ':' splitting in patch headers (e.g., *** Update File: D:\...) and adds a regression test to cover all supported header types with drive-letter paths.
Changes:
- Update patch header parsing to slice the path substring after the known header prefix rather than splitting on
:. - Add a regression test ensuring Windows drive-letter paths are parsed correctly for
Add File,Delete File,Update File, andMove to.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| packages/opencode/src/patch/index.ts | Fixes header path extraction to preserve Windows drive-letter colons. |
| packages/opencode/test/patch/patch.test.ts | Adds a regression test covering colon-containing (drive-letter) paths across header types. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Copilot approves as well, the fix is minimal and should solve most of the problems. |
Summary
parsePatchHeaderusedline.split(':', 2)to extract file paths from headers like*** Update File: D:\path\file.ts. On Windows, the colon in the drive letter (e.g.D:) causedsplitto truncate the path to just the drive letter, producing invalid resolved paths like<project_dir>\D.split(':')withslice()after the known prefix length so the full path including drive letter is preserved.Add File,Delete File,Update File,Move to) with Windows drive-letter paths.Reproduction
When a model generates a patch with an absolute Windows path:
The parser splits on
:and gets["*** Update File", " D"], truncating the path toD. This is then resolved aspath.resolve(projectDir, "D")producing e.g.D:\repos\project\D, which fails with:Fixes #10360. Related to #11687.