Skip to content

Commit c5490d9

Browse files
TarasusrusRomneyDa
andauthored
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>
1 parent afd5e5e commit c5490d9

File tree

2 files changed

+16
-1
lines changed
  • extensions/intellij/src
    • main/kotlin/com/github/continuedev/continueintellijextension/continue
    • test/kotlin/com/github/continuedev/continueintellijextension/unit

2 files changed

+16
-1
lines changed

extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/continue/UriUtils.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ object UriUtils {
2626
// Handle Windows file paths with authority component
2727
if (uriStr.startsWith("file://") && !uriStr.startsWith("file:///")) {
2828
val path = uriStr.substringAfter("file://")
29-
return URI("file:///$path")
29+
return URI("file", "", "/$path", null)
3030
}
3131

3232
return try {

extensions/intellij/src/test/kotlin/com/github/continuedev/continueintellijextension/unit/UriUtilsTest.kt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,19 @@ class UriUtilsTest : TestCase() {
6060
val expectedFile = File("/path/to/file with spaces")
6161
assertEquals(expectedFile, result)
6262
}
63+
64+
// Regression test for #10978 — bracket directories like [gamemode]
65+
fun `test square brackets in path`() {
66+
val uri = "file:///path/to/[gamemode]/file.lua"
67+
val result = UriUtils.uriToFile(uri)
68+
assertEquals(File("/path/to/[gamemode]/file.lua"), result)
69+
}
70+
71+
fun `test Windows path with square brackets`() {
72+
val uri = "file://C:/Users/user/projects/[gamemode]/file.lua"
73+
val parsed = UriUtils.parseUri(uri)
74+
assertEquals("file", parsed.scheme)
75+
assertEquals("/C:/Users/user/projects/[gamemode]/file.lua", parsed.path)
76+
assertEquals("file:///C:/Users/user/projects/%5Bgamemode%5D/file.lua", parsed.toString())
77+
}
6378
}

0 commit comments

Comments
 (0)