-
Notifications
You must be signed in to change notification settings - Fork 5.6k
fix(app) TypeError: Failed to execute 'set' on 'Headers': String contains non IS0-8859-1 code point. #7031
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
The following comment was made by an LLM, it may be inaccurate: ResultNo duplicate PRs found. All search queries returned only the current PR (#7031), indicating this is a unique issue that hasn't been addressed in other open PRs. The searches covered:
This appears to be a novel fix for handling Unicode characters in filesystem paths when they're passed through HTTP headers in a Tauri/WebView environment. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR fixes a TypeError that occurs in Tauri/WebView environments when filesystem paths containing Unicode characters are passed via HTTP headers. The Headers.set() API in WebView only accepts ISO-8859-1 characters, causing crashes when raw filesystem paths with Unicode are used.
Key changes:
- SDK clients (v1 and v2) now URL-encode the directory path with an
opencode-uri:prefix before setting the header - Server-side middleware detects and decodes the prefixed header value to restore the original path
- Headers handling logic updated to support different header types (Headers object, array, plain object)
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| packages/sdk/js/src/v2/client.ts | Adds encoding logic for directory header with opencode-uri prefix to prevent Unicode-related crashes in WebView |
| packages/sdk/js/src/client.ts | Identical encoding logic applied to v1 client for consistency |
| packages/opencode/src/server/server.ts | Adds decoding middleware to handle the encoded directory header from clients |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| const directory = c.req.query("directory") || c.req.header("x-opencode-directory") || process.cwd() | ||
| const rawDirectory = c.req.query("directory") || c.req.header("x-opencode-directory") || process.cwd() | ||
| const directory = (() => { | ||
| const prefix = "opencode-uri:" |
Copilot
AI
Jan 6, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The prefix constant is defined inline in the server code but as a constant in the SDK files. This creates a maintenance risk where the prefix strings could become out of sync. Consider extracting this to a shared constant or at minimum using a named constant here as well for consistency and easier maintenance.
| const directory = (() => { | ||
| const prefix = "opencode-uri:" |
Copilot
AI
Jan 6, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The IIFE pattern here defines the prefix constant inside the function scope. Since this middleware runs on every request and the prefix is a constant value, consider defining it at the module level alongside OPENCODE_DIRECTORY_HEADER_PREFIX in the SDK files for better performance and consistency.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot open a new pull request to apply changes based on this feedback
|
/review |
| ...config, | ||
| headers, | ||
| } | ||
| } else { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Style guide suggestion: The else statement here could potentially be avoided using early return pattern. For example, handling the object case first and returning early would eliminate the need for else. However, this is a minor suggestion - the current implementation is clear and readable, so feel free to keep it as-is if you prefer.
| ...config, | ||
| headers, | ||
| } | ||
| } else { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Style guide suggestion: The else statement here could potentially be avoided using early return pattern. For example, handling the object case first and returning early would eliminate the need for else. However, this is a minor suggestion - the current implementation is clear and readable, so feel free to keep it as-is if you prefer.
9e2c067 to
70d078a
Compare
…and improve header management
Co-authored-by: Copilot <[email protected]>
70d078a to
d3e69e1
Compare
|
closing in favor of #7145 |
Why it crashed
mergeConfigs() calls mergeHeaders(), which ends up doing Headers.set(...). In Tauri/WebView, Headers.set() throws if the header key/value contains characters outside ISO‑8859‑1. We were putting a raw filesystem path into x-opencode-directory, and paths can contain Unicode.
Fix (implemented)
SDK: URL-encode the directory header as opencode-uri: + encodeURIComponent(directory) (done for both v1 + v2 clients).
Server: If the incoming directory value starts with opencode-uri:, decode it before using it.