Skip to content

fix(intellij): handle square brackets in file paths for autocomplete#11474

Open
Tarasusrus wants to merge 3 commits intocontinuedev:mainfrom
Tarasusrus:fix/intellij-uri-square-brackets
Open

fix(intellij): handle square brackets in file paths for autocomplete#11474
Tarasusrus wants to merge 3 commits intocontinuedev:mainfrom
Tarasusrus:fix/intellij-uri-square-brackets

Conversation

@Tarasusrus
Copy link

@Tarasusrus Tarasusrus commented Mar 16, 2026

Use File.toURI() instead of URI constructor for Windows two-slash
file:// URIs to properly percent-encode special characters like [ ].
Fixes #10978.


Summary by cubic

Fixes URI parsing for file paths with square brackets to prevent IntelliJ autocomplete crashes on Windows two‑slash file URIs. Builds Windows file://C:/... URIs via File.toURI() so [ and ] are percent‑encoded.

  • Bug Fixes
    • Update UriUtils to handle Windows two‑slash file:// URIs using File.toURI() instead of URI(...).
    • Add regression tests for Unix and Windows; make the Windows-style test cross‑platform by asserting bracket encoding and path structure without drive‑letter assumptions.

Written for commit a00c389. Summary will update on new commits.

@dosubot dosubot bot added the size:S This PR changes 10-29 lines, ignoring generated files. label Mar 16, 2026
@github-actions
Copy link
Contributor

github-actions bot commented Mar 16, 2026

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@Tarasusrus
Copy link
Author

I have read the CLA Document and I hereby sign the CLA.

Use File.toURI() instead of URI constructor for Windows two-slash
file:// URIs to properly percent-encode special characters like [ ].
Fixes continuedev#10978.
@Tarasusrus Tarasusrus force-pushed the fix/intellij-uri-square-brackets branch from 6e4b338 to 609cf8f Compare March 16, 2026 04:50
@Tarasusrus Tarasusrus requested a review from a team as a code owner March 16, 2026 04:50
@Tarasusrus Tarasusrus requested review from RomneyDa and removed request for a team March 16, 2026 04:50
Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

2 issues found across 2 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/continue/UriUtils.kt">

<violation number="1" location="extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/continue/UriUtils.kt:30">
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.</violation>
</file>

<file name="extensions/intellij/src/test/kotlin/com/github/continuedev/continueintellijextension/unit/UriUtilsTest.kt">

<violation number="1" location="extensions/intellij/src/test/kotlin/com/github/continuedev/continueintellijextension/unit/UriUtilsTest.kt:85">
P2: Windows regression test assertions are too weak to catch drive-letter or bracket-handling regressions in `file://C:/...` URIs.</violation>
</file>

Since this is your first cubic review, here's how it works:

  • cubic automatically reviews your code and comments on bugs and improvements
  • Teach cubic by replying to its comments. cubic learns from your replies and gets better over time
  • Add one-off context when rerunning by tagging @cubic-dev-ai with guidance or docs links (including llms.txt)
  • Ask questions if you need clarification on any suggestion

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

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

Verify that square brackets are percent-encoded and drive letter
and directory structure are preserved in parsed URI path.
@dosubot dosubot bot added size:M This PR changes 30-99 lines, ignoring generated files. and removed size:S This PR changes 10-29 lines, ignoring generated files. labels Mar 16, 2026
Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

1 issue found across 1 file (changes from recent commits).

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="extensions/intellij/src/test/kotlin/com/github/continuedev/continueintellijextension/unit/UriUtilsTest.kt">

<violation number="1" location="extensions/intellij/src/test/kotlin/com/github/continuedev/continueintellijextension/unit/UriUtilsTest.kt:86">
P2: Test incorrectly expects percent-encoded brackets in `URI.path`; `path` is decoded for `java.net.URI`, so this assertion is invalid.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

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.
Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

1 issue found across 1 file (changes from recent commits).

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="extensions/intellij/src/test/kotlin/com/github/continuedev/continueintellijextension/unit/UriUtilsTest.kt">

<violation number="1" location="extensions/intellij/src/test/kotlin/com/github/continuedev/continueintellijextension/unit/UriUtilsTest.kt:86">
P2: Windows bracket-path regression test was weakened and no longer asserts key Windows URI guarantees (encoding/preservation), allowing incorrect rewrites to pass.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

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

@RomneyDa
Copy link
Collaborator

@Tarasusrus could you check the cubic comment? seems potentially valid

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:M This PR changes 30-99 lines, ignoring generated files.

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

Autocomplete crashes with files having square brackets in the filepath/filename.

2 participants