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:
Taras Malinovskii 2026-03-27 05:12:38 +07:00 • committed by GitHub
parent afd5e5e18f
commit c5490d97ea
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 16 additions and 1 deletions

View file

@ -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 {

View file

@ -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())
}
}