SyntaxError: CSS selector not properly escaped for file paths with special characters #6650

Open
opened 2026-02-16 18:04:51 -05:00 by yindo · 1 comment
Owner

Originally created by @ma-pony on GitHub (Jan 17, 2026).

Originally assigned to: @adamdotdevin on GitHub.

Description

When a file path contains file:// prefix and non-ASCII characters (e.g., Chinese), the CSS selector fails with:

SyntaxError: '[data-key="file://"output/20260118_095332_末世冰封_我搬空全球超市造神域.md""]' is not a valid selector.

Stack Trace

querySelector@[native code]
@tauri://localhost/assets/session-CCDakWO3.js:30:6115
Cb@tauri://localhost/assets/index-D9T6R7qf.js:2:8252
$l@tauri://localhost/assets/index-D9T6R7qf.js:2:7983
Ld@tauri://localhost/assets/index-D9T6R7qf.js:2:9468
Qk@tauri://localhost/assets/index-D9T6R7qf.js:2:10732
yn@tauri://localhost/assets/index-D9T6R7qf.js:2:9656
Jk@tauri://localhost/assets/index-D9T6R7qf.js:2:10317
yn@tauri://localhost/assets/index-D9T6R7qf.js:2:9668
D@tauri://localhost/assets/index-D9T6R7qf.js:2:3812
M@tauri://localhost/assets/index-D9T6R7qf.js:2:3770

Root Cause

The file path is not being escaped before being used in querySelector. The selector contains unescaped quotes and special characters.

Suggested Fix

Use CSS.escape() when building the selector:

// Before (broken)
document.querySelector(\`[data-key="\${key}"]\`);

// After (fixed)
document.querySelector(\`[data-key="\${CSS.escape(key)}"]\`);

Environment

  • OpenCode Desktop (Tauri)
  • File path with Chinese characters

Workaround

Avoid using non-ASCII characters in file names.

Originally created by @ma-pony on GitHub (Jan 17, 2026). Originally assigned to: @adamdotdevin on GitHub. ## Description When a file path contains `file://` prefix and non-ASCII characters (e.g., Chinese), the CSS selector fails with: ``` SyntaxError: '[data-key="file://"output/20260118_095332_末世冰封_我搬空全球超市造神域.md""]' is not a valid selector. ``` ## Stack Trace ``` querySelector@[native code] @tauri://localhost/assets/session-CCDakWO3.js:30:6115 Cb@tauri://localhost/assets/index-D9T6R7qf.js:2:8252 $l@tauri://localhost/assets/index-D9T6R7qf.js:2:7983 Ld@tauri://localhost/assets/index-D9T6R7qf.js:2:9468 Qk@tauri://localhost/assets/index-D9T6R7qf.js:2:10732 yn@tauri://localhost/assets/index-D9T6R7qf.js:2:9656 Jk@tauri://localhost/assets/index-D9T6R7qf.js:2:10317 yn@tauri://localhost/assets/index-D9T6R7qf.js:2:9668 D@tauri://localhost/assets/index-D9T6R7qf.js:2:3812 M@tauri://localhost/assets/index-D9T6R7qf.js:2:3770 ``` ## Root Cause The file path is not being escaped before being used in `querySelector`. The selector contains unescaped quotes and special characters. ## Suggested Fix Use `CSS.escape()` when building the selector: ```javascript // Before (broken) document.querySelector(\`[data-key="\${key}"]\`); // After (fixed) document.querySelector(\`[data-key="\${CSS.escape(key)}"]\`); ``` ## Environment - OpenCode Desktop (Tauri) - File path with Chinese characters ## Workaround Avoid using non-ASCII characters in file names.
yindo added the web label 2026-02-16 18:04:51 -05:00
Author
Owner

@github-actions[bot] commented on GitHub (Jan 17, 2026):

This issue might be a duplicate of existing issues. Please check:

  • #9031: The desktop app crashes with packages/ui/src/components/list.tsx data-key element - Same CSS selector error with Chinese characters in file names
  • #8172: OpenCode 桌面版 不支持读取中文名文件 - Same SyntaxError with Chinese file names causing selector failures

Both issues report the exact same root cause: unescaped special characters in the data-key attribute being used in querySelector calls.

Feel free to ignore if none of these address your specific case.

@github-actions[bot] commented on GitHub (Jan 17, 2026): This issue might be a duplicate of existing issues. Please check: - #9031: The desktop app crashes with packages/ui/src/components/list.tsx data-key element - Same CSS selector error with Chinese characters in file names - #8172: OpenCode 桌面版 不支持读取中文名文件 - Same SyntaxError with Chinese file names causing selector failures Both issues report the exact same root cause: unescaped special characters in the data-key attribute being used in querySelector calls. Feel free to ignore if none of these address your specific case.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#6650