fix(intellij): handle square brackets in file paths for autocomplete (#11474)
* fix(intellij): handle square brackets in file paths for autocomplete Use File.toURI() instead of URI constructor for Windows two-slash file:// URIs to properly percent-encode special characters like [ ]. Fixes #10978. * test(intellij): strengthen Windows URI assertions for bracket encoding Verify that square brackets are percent-encoded and drive letter and directory structure are preserved in parsed URI path. * fix(intellij): make Windows bracket test cross-platform The CI runs on Linux where C: is not a drive letter. Assert that brackets are encoded and structure is preserved without platform-specific path assumptions. * fix: use cross-platform URI constructor instead of File.toURI() File.toURI() is platform-dependent — on non-Windows hosts it treats Windows drive paths (e.g. C:/Users/...) as relative paths, producing corrupted URIs. The multi-arg URI(scheme, host, path, fragment) constructor is pure RFC 2396 string manipulation and works identically on all platforms. Also strengthens the Windows bracket test with exact equality assertions instead of loose contains/assertFalse checks. * chore: remove verbose comments for minimal diff --------- Co-authored-by: Dallin Romney <dallinromney@gmail.com>
This commit is contained in:
parent
afd5e5e18f
commit
c5490d97ea
2 changed files with 16 additions and 1 deletions
|
|
@ -26,7 +26,7 @@ object UriUtils {
|
|||
// Handle Windows file paths with authority component
|
||||
if (uriStr.startsWith("file://") && !uriStr.startsWith("file:///")) {
|
||||
val path = uriStr.substringAfter("file://")
|
||||
return URI("file:///$path")
|
||||
return URI("file", "", "/$path", null)
|
||||
}
|
||||
|
||||
return try {
|
||||
|
|
|
|||
|
|
@ -60,4 +60,19 @@ class UriUtilsTest : TestCase() {
|
|||
val expectedFile = File("/path/to/file with spaces")
|
||||
assertEquals(expectedFile, result)
|
||||
}
|
||||
|
||||
// Regression test for #10978 — bracket directories like [gamemode]
|
||||
fun `test square brackets in path`() {
|
||||
val uri = "file:///path/to/[gamemode]/file.lua"
|
||||
val result = UriUtils.uriToFile(uri)
|
||||
assertEquals(File("/path/to/[gamemode]/file.lua"), result)
|
||||
}
|
||||
|
||||
fun `test Windows path with square brackets`() {
|
||||
val uri = "file://C:/Users/user/projects/[gamemode]/file.lua"
|
||||
val parsed = UriUtils.parseUri(uri)
|
||||
assertEquals("file", parsed.scheme)
|
||||
assertEquals("/C:/Users/user/projects/[gamemode]/file.lua", parsed.path)
|
||||
assertEquals("file:///C:/Users/user/projects/%5Bgamemode%5D/file.lua", parsed.toString())
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue