Fix percent-encoded drive letter colon (%3A) in Windows file URIs#11293
Open
ActaVerba wants to merge 1 commit intomicrosoft:mainfrom
Open
Fix percent-encoded drive letter colon (%3A) in Windows file URIs#11293ActaVerba wants to merge 1 commit intomicrosoft:mainfrom
ActaVerba wants to merge 1 commit intomicrosoft:mainfrom
Conversation
Some LSP clients send file URIs with the drive letter colon percent-encoded as %3A (e.g., file:///c%3A/Users/...). The existing _dosPathRegex only matches literal colons, causing getFilePath() to fail to strip the leading slash and decode the path correctly on Windows. - Update _dosPathRegex to also match %3A/%3a after the drive letter - Decode percent-encoded colon back to ':' after stripping the leading slash
Collaborator
|
Can you add some unit tests for your scenario to make sure this doesn't regress again? There should be a set of unit tests for URIs. |
|
I wonder if there are other characters being encoded the same way, and if an approach other than string replacement would exist |
Collaborator
This is the only character we're looking for. It's specifically for finding drives on Windows. I suppose it's possible it could be translated a different way, but I've not seen that before. |
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.
Summary
Some LSP clients send file URIs with the drive letter colon percent-encoded as
%3A(e.g.,file:///c%3A/Users/...). The existing_dosPathRegexingetFilePath()only matches literal colons, causing it to fail to strip the leading slash and decode the path correctly on Windows.This results in invalid file paths that break path resolution, particularly when using
--threadsfor parallel type checking (where URIs are serialized between worker threads).Changes
_dosPathRegexto also match%3A/%3aafter the drive letter:/^\/[a-zA-Z](?::|%3[aA])\//%3A/%3aback to:after stripping the leading slashTest
Before fix:
file:///c%3A/Users/project/file.py→/c%3A/Users/project/file.py(broken path)After fix:
file:///c%3A/Users/project/file.py→c:/Users/project/file.py(correct path)Verified with
pyright --threads autoon a real Windows project — paths resolve correctly.