Skip to content

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

Closed

Description

@ma-pony

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.

Activity

  1. github-actions commented on Jan 18, 2026

    @github-actions
    Contributor

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

    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.

  2. github-actions commented on Mar 27, 2026

    @github-actions
    Contributor

    To stay organized issues are automatically closed after 90 days of no activity. If the issue is still relevant please open a new one.

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

Metadata

Metadata

Assignees

Labels

webRelates to opencode on web / desktop

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions