Skip to content

Normalize Windows drive letter case in workspace document URIs - #719

Open
Sanjays2402 wants to merge 2 commits into
python-lsp:developfrom
Sanjays2402:fix/normalize-drive-letter-doc-uris
Open

Normalize Windows drive letter case in workspace document URIs#719
Sanjays2402 wants to merge 2 commits into
python-lsp:developfrom
Sanjays2402:fix/normalize-drive-letter-doc-uris

Conversation

@Sanjays2402

Copy link
Copy Markdown

Closes #697

Windows drive letters are case-insensitive, so a client may send file:///C:/foo (RFC 8089) or file:///c:/foo for the same file. uris.from_fs_path lower-cases the drive letter but Workspace._docs stored URIs verbatim, so the two spellings became separate dictionary keys — a document opened under one spelling was invisible under the other, and lookups silently fell back to stale on-disk content instead of the in-memory version.

Adds uris.normalize and uses it for every _docs key. Non-drive paths are unchanged. New tests fail without the fix and pass with it.

Windows drive letters are case-insensitive and clients may send either
`file:///C:/foo` (RFC 8089) or `file:///c:/foo` for the same file.
`uris.from_fs_path` lower-cases the drive letter, but `Workspace._docs`
stored URIs verbatim, so the two spellings became distinct dictionary
keys. A document opened under one spelling was then invisible under the
other, and lookups silently fell back to reading stale content from disk
instead of the in-memory version.

Add `uris.normalize` and use it for every `_docs` key, so a document is
found regardless of the drive letter case the client used. Non-drive
paths are unchanged.
@ccordoba12

Copy link
Copy Markdown
Member

Hey @Sanjays2402, thanks for your contribution! There's a test that started to fail on Windows due to your changes. Please try to fix it.

Workspace._docs is now keyed by uris.normalize(doc_uri), so on Windows a
client-sent 'file:///C:/...' URI is stored as 'file:///c:/...'. The
multiple-workspaces tests inspect _docs directly with the raw message
URI, which no longer matches on Windows. Normalize the expected key in
those assertions; behaviour on other platforms is unchanged.
@Sanjays2402

Copy link
Copy Markdown
Author

Fixed. The failure was drive-letter case in test_multiple_workspaces and test_multiple_workspaces_from_initialize: both peek directly into the private _docs dict with the raw client URI (file:///C:/...), but this PR keys that dict via uris.normalize(), which lower-cases the drive letter as uris.from_fs_path already did. So it was the test expectation that went stale, not the code over-normalizing — the public get_maybe_document() path was fine throughout. Wrapped the six _docs membership assertions in uris.normalize(); left the public-API and pylsp.workspaces folder-URI assertions alone since those keys aren't normalized. Pushed 6174437. Verified locally on macOS, where normalize() is a no-op, so Windows CI on this SHA is the real check.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants