Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@ object UriUtils {
// Remove query parameters if present
val uriStr = uri.substringBefore("?")

// Handle Windows file paths with authority component
// Handle Windows file paths with authority component (e.g. file://C:/path/to/file)
// Use File.toURI() to properly percent-encode special characters like [ ] in paths
if (uriStr.startsWith("file://") && !uriStr.startsWith("file:///")) {
val path = uriStr.substringAfter("file://")
return URI("file:///$path")
return File(path).toURI()
Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot Mar 16, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1: File(path).toURI() reparses file:// URI text as a host-local path, causing cross-platform URI corruption and double-encoding of already escaped segments.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/continue/UriUtils.kt, line 30:

<comment>`File(path).toURI()` reparses `file://` URI text as a host-local path, causing cross-platform URI corruption and double-encoding of already escaped segments.</comment>

<file context>
@@ -23,10 +23,11 @@ object UriUtils {
         if (uriStr.startsWith("file://") && !uriStr.startsWith("file:///")) {
             val path = uriStr.substringAfter("file://")
-            return URI("file:///$path")
+            return File(path).toURI()
         }
 
</file context>
Fix with Cubic

}

return try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,34 @@ class UriUtilsTest : TestCase() {
val expectedFile = File("/path/to/file with spaces")
assertEquals(expectedFile, result)
}

/**
* Validates that square brackets in file paths are handled correctly.
* This is a regression test for GitHub issue #10978.
* Frameworks like Next.js and FiveM use bracket-named directories
* (e.g. [gamemode]) which caused URI parsing to crash.
*/
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)
}

/**
* Validates that Windows-style file URIs with square brackets are handled.
* Regression test for GitHub issue #10978 — the original crash occurred
* specifically with Windows two-slash file:// URIs.
*/
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)
// Brackets must be percent-encoded or absent as raw characters in a valid URI
assertFalse("Raw square brackets should not appear in URI path",
Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot Mar 16, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: Windows bracket-path regression test was weakened and no longer asserts key Windows URI guarantees (encoding/preservation), allowing incorrect rewrites to pass.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At extensions/intellij/src/test/kotlin/com/github/continuedev/continueintellijextension/unit/UriUtilsTest.kt, line 86:

<comment>Windows bracket-path regression test was weakened and no longer asserts key Windows URI guarantees (encoding/preservation), allowing incorrect rewrites to pass.</comment>

<file context>
@@ -82,11 +82,12 @@ class UriUtilsTest : TestCase() {
-            parsed.path.contains("C:") || parsed.path.contains("c:"))
-        assertTrue("Path should preserve full directory structure",
+        // Brackets must be percent-encoded or absent as raw characters in a valid URI
+        assertFalse("Raw square brackets should not appear in URI path",
+            parsed.toString().contains("[") || parsed.toString().contains("]"))
+        assertTrue("Path should preserve directory structure",
</file context>
Fix with Cubic

parsed.toString().contains("[") || parsed.toString().contains("]"))
assertTrue("Path should preserve directory structure",
parsed.path.contains("Users/user/projects"))
assertTrue("Path should end with file name",
parsed.path.endsWith("file.lua"))
}
}
Loading