Skip to content

fix(app): handle Windows paths in frontend file URL encoding#12601

Merged
adamdotdevin merged 1 commit intoanomalyco:devfrom
yudgnahk:fix/windows-path-encoding-frontend
Feb 7, 2026
Merged

fix(app): handle Windows paths in frontend file URL encoding#12601
adamdotdevin merged 1 commit intoanomalyco:devfrom
yudgnahk:fix/windows-path-encoding-frontend

Conversation

@yudgnahk
Copy link
Contributor

@yudgnahk yudgnahk commented Feb 7, 2026

Fixes #12424 (comment: #12424 (comment))

Summary

Fixes bug introduced in PR #12424 where Windows users cannot mention files. The frontend's encodeFilePath() function doesn't handle Windows backslashes, causing invalid file:// URLs on Windows.

Root Cause

Frontend path encoding splits by / but Windows uses \. Paths like D:\dev\projects\opencode\README.md get encoded as D%3A%5Cdev%5Cprojects%5C... instead of /D:/dev/projects/..., resulting in invalid file:// URLs:

TypeError: "file://D%3A%5Cdev%5Cprojects%5Copencode/README.bs.md" cannot be parsed as a URL.

Solution

Changes

Frontend Files (4 files)

  • packages/app/src/context/file/path.ts - Updated encodeFilePath() to handle Windows backslashes
  • packages/app/src/components/prompt-input/build-request-parts.ts - Updated duplicate encodeFilePath() function
  • packages/app/src/context/file/path.test.ts - Added 34 new tests for Windows/Linux/macOS paths
  • packages/app/src/components/prompt-input/build-request-parts.test.ts - Added 8 integration tests

Testing

46 tests pass, 0 fail - All unit and integration tests
TypeScript clean - No type errors
Windows paths: Tests exact bug scenario from @alexyaroshuk
Cross-platform: Tests Windows (D:\path), Linux (/path), macOS paths
Special chars: Tests #, ?, %, spaces in filenames
Backward compatible: Normal paths produce identical output

Impact

Fixes:

  • File mentioning with @ on Windows (reported by @alexyaroshuk)
  • File URL construction for Windows absolute paths
  • Cross-platform compatibility for path encoding

4 files changed, 149 insertions(+), 8 deletions(-)

Verification

@alexyaroshuk Can you verify this fixes the file mentioning issue on your Windows machine?

Fixes Windows path encoding in frontend's encodeFilePath() function that
was causing ERR_INVALID_URL errors when mentioning files on Windows.

The frontend encodeFilePath() function didn't handle Windows backslashes,
causing paths like D:\path\file.txt to be encoded as D%3A%5Cpath%5C...
which creates invalid file:// URLs. This only affected the frontend since
the backend correctly uses pathToFileURL() from Bun.

Changes:
- Normalize Windows backslashes to forward slashes
- Add leading / for Windows absolute paths (D: -> /D:)
- Preserve proper encoding for special characters (#, ?, %, spaces)

Testing:
- 46 tests added (36 unit, 10 integration)
- Covers Windows, Linux, macOS paths
- Tests exact bug scenario, edge cases, cross-platform compatibility
- All existing tests still pass
@github-actions
Copy link
Contributor

github-actions bot commented Feb 7, 2026

Thanks for your contribution!

This PR doesn't have a linked issue. All PRs must reference an existing issue.

Please:

  1. Open an issue describing the bug/feature (if one doesn't exist)
  2. Add Fixes #<number> or Closes #<number> to this PR description

See CONTRIBUTING.md for details.

@github-actions
Copy link
Contributor

github-actions bot commented Feb 7, 2026

The following comment was made by an LLM, it may be inaccurate:

No duplicate PRs found

@yudgnahk
Copy link
Contributor Author

yudgnahk commented Feb 7, 2026

Related to #12424 comment by @alexyaroshuk
Hi Alex, could you pull this branch and help me test in your local, please?

I do not have the windows machine :D

@yudgnahk
Copy link
Contributor Author

yudgnahk commented Feb 7, 2026

Hi @adamdotdevin, please help me review the PR before releasing the new version. I don't want to harm the windows version...

@alexyaroshuk
Copy link
Contributor

Related to #12424 comment by @alexyaroshuk Hi Alex, could you pull this branch and help me test in your local, please?

I do not have the windows machine :D

Just tested - the bug is fixed in this pr.

@yudgnahk
Copy link
Contributor Author

yudgnahk commented Feb 7, 2026

Just tested - the bug is fixed in this pr.

Thank you @alexyaroshuk!

@yudgnahk
Copy link
Contributor Author

yudgnahk commented Feb 7, 2026

Hi @rekram1-node could you help me review this PR please? Thank you!

@adamdotdevin adamdotdevin merged commit 4efbfcd into anomalyco:dev Feb 7, 2026
8 checks passed
@yudgnahk yudgnahk deleted the fix/windows-path-encoding-frontend branch February 9, 2026 02:39
fanjia1024 pushed a commit to fanjia1024/opencode that referenced this pull request Feb 10, 2026
BryceRyan pushed a commit to BryceRyan/opencode that referenced this pull request Feb 10, 2026
avion23 pushed a commit to avion23/opencode that referenced this pull request Feb 13, 2026
relaxkeren pushed a commit to relaxkeren/opencode that referenced this pull request Feb 15, 2026
schneiderlo pushed a commit to schneiderlo/opencode that referenced this pull request Feb 17, 2026
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.

3 participants

Comments