Fix normalized URI generation for UNC path#374
Fix normalized URI generation for UNC path#374Friendseeker wants to merge 1 commit intosbt:developfrom
Conversation
| def directoryURI(dir: File): URI = { | ||
| assertAbsolute(dir) | ||
| directoryURI(dir.toURI.normalize) | ||
| directoryURI(dir.toPath.normalize.toUri) |
There was a problem hiding this comment.
Could we add unit test for this plz?
| new URI(str + "/") | ||
|
|
||
| dirURI.normalize | ||
| new File(dirURI).toPath.normalize.toUri |
There was a problem hiding this comment.
The creation of the first URI object seems wasteful here. See also #132, which states that URI object can lead to hundreds of MB in heap.
There was a problem hiding this comment.
Shall investigate this once I regain access to a Windows Machine.
Indeed there is something fishy there. If dirURI follows u2 notation, then calling dirURI.normalize should be correct. While I think the other changes in the PR makes sense, this particular change is just a bandaid that somehow fixes the sbt crash without fixing the underlying issue.
I now actually suspect the hidden issue might be with IO.toURL, which is called by ProjectRef.apply on sbt side. This is just a hypothesis though.
There was a problem hiding this comment.
Btw going slightly off topic but your blogpost about file URI schema is so helpful! Without it I probably need to spend a lot of time researching about file URI.
|
I must say this is more complex than I anticipated... The PR, as of its current state, is inadequate. The issue is that, the dollar sign actually matters when parsing a URI. Probably since $ is a reserved character. The u4 URI is fragile. After calling So here's the current state:
|
Issue
IO.directoryURIandPath.absoluteboth callstoURI.normalizeto convert ajava.io.Fileto a normalized URI, which generates invalid URI for UNC path. As a result, sbt crashes when we try to open a project in a WSL directory.Example: say we have a
dir: java.io.FilerepresentingUbuntu-24.04/home/jerrytan/testwsl/in WSL, then callingdir.toPath.toUri.normalizeyieldsfile:/wsl$/Ubuntu-24.04/home/jerrytan/testwsl/, which then leads toFix
Call
toPath.normalize.toUriinstead. For above example, it yieldsfile:////wsl$/Ubuntu-24.04/home/jerrytan/testwsl/which can be loaded by sbt. Note that the new file URL still do not follow the best practice as documented in Eugene's blog post, but it indeed do not crash.Closes sbt/sbt#7135
Credit to reporter of sbt/sbt#7135 for detailed investigation of the issue.