Skip to content

Fix parsing/generating Windows-style file: URIs#2572

Merged
dantleech merged 1 commit intophpactor:masterfrom
MatmaRex:windows-file-uri
Mar 2, 2024
Merged

Fix parsing/generating Windows-style file: URIs#2572
dantleech merged 1 commit intophpactor:masterfrom
MatmaRex:windows-file-uri

Conversation

@MatmaRex
Copy link
Contributor

This fixes features like "go to definition" on Windows.

In a file: URI, after the scheme, there are two slashes, then the 'host' (usually empty), then another slash, then the 'path'. For example:

file:///foo/bar.php
file:///C:/foo/bar.php

That's three leading slashes total, and the third slash is not a part of the path, but a part of the URI format itself; it just looks like that with Unix-style filesystem paths.

Unfortunately, this means you can't just prepend 'file://' to a filesystem path and get a valid file: URI. Fortunately, TextDocumentUri::fromString(…) accepts filesystem paths too, so document that and use it in test cases. Replace invalid URIs with two slashes in other test cases too to avoid confusion.

See: https://en.wikipedia.org/wiki/File_URI_scheme

@MatmaRex
Copy link
Contributor Author

This is a bit of a follow-up for #2568, after I better understood how things work.

This fixes features like "go to definition" on Windows.

In a file: URI, after the scheme, there are two slashes, then
the 'host' (usually empty), then another slash, then the 'path'.
For example:

  file:///foo/bar.php
  file:///C:/foo/bar.php

That's three leading slashes total, and the third slash is not
a part of the path, but a part of the URI format itself; it just
looks like that with Unix-style filesystem paths.

Unfortunately, this means you can't just prepend 'file://'
to a filesystem path and get a valid file: URI. Fortunately,
`TextDocumentUri::fromString(…)` accepts filesystem paths too,
so document that and use it in test cases. Replace invalid URIs
with two slashes in other test cases too to avoid confusion.

See: https://en.wikipedia.org/wiki/File_URI_scheme
@dantleech
Copy link
Collaborator

nice work!

@MatmaRex MatmaRex deleted the windows-file-uri branch April 4, 2024 17:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants