-
Notifications
You must be signed in to change notification settings - Fork 941
fix: handle UTF BOM in config files #10154
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
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
🦋 Changeset detectedLatest commit: b4df46e The changes in this PR will be included in the next version bump. This PR includes changesets to release 3 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Failed to automatically backport this PR's changes to Wrangler v3. Please manually create a PR targeting the Depending on your changes, running Notes:
|
create-cloudflare
@cloudflare/kv-asset-handler
miniflare
@cloudflare/pages-shared
@cloudflare/unenv-preset
@cloudflare/vite-plugin
@cloudflare/vitest-pool-workers
@cloudflare/workers-editor-shared
wrangler
commit: |
Hey Devin e08929d was actually great - you can probably collapse the "name" and "encoding" properties as they are the same - you should keep encoding with has a nicer description. Why did you not kept that commit? |
- Remove UTF-8 BOM (ef bb bf) from config files before parsing - Throw descriptive errors for other BOMs (UTF-16, UTF-32) - Add comprehensive tests for BOM handling in TOML and JSON configs Fixes #9938 Co-Authored-By: [email protected] <[email protected]>
- Replace individual BOM constants with UNSUPPORTED_BOMS array - Use loop instead of separate if statements for each BOM type - Reduces code duplication while maintaining exact same functionality Addresses PR feedback from vicb Co-Authored-By: [email protected] <[email protected]>
- Use TextDecoder().decode() first, which automatically strips UTF-8 BOMs - Check for UTF-16/UTF-32 BOMs as replacement characters in decoded string - Fall back to raw buffer inspection to determine specific BOM type - Cleaner approach as suggested by user feedback - All existing tests continue to pass Co-Authored-By: [email protected] <[email protected]>
- TextDecoder().decode() first to automatically strip UTF-8 BOMs - Check for replacement characters to detect non-UTF-8 BOMs - Fall back to raw buffer inspection for specific BOM type identification - All BOM tests pass (UTF-8 removal, UTF-16/UTF-32 error detection) - Constant string approach not viable as all non-UTF-8 BOMs decode identically Co-Authored-By: [email protected] <[email protected]>
- Apply prettier formatting to parse.ts - No functional changes to BOM detection logic - All BOM tests continue to pass locally Co-Authored-By: [email protected] <[email protected]>
35c15bf
to
54428f1
Compare
… and array-based BOM detection - Update UTF-8 BOM tests to use Buffer.concat([Buffer.from([0xEF, 0xBB, 0xBF]), Buffer.from(configContent, 'utf-8')]) as suggested by petebacondarwin - Revert to array-based BOM detection approach with collapsed properties (name + encoding) as suggested by vicb - Maintain all existing functionality while following preferred patterns Co-Authored-By: [email protected] <[email protected]>
Congratulations @devin-ai-integration[bot], the maintainer of this repository has issued you a holobyte! Here it is: https://holopin.io/holobyte/cmdshoz8f665807jydb6r3n2l This badge can only be claimed by you, so make sure that your GitHub account is linked to your Holopin account. You can manage those preferences here: https://holopin.io/account. |
Fixes #9938.
This PR implements UTF BOM (Byte Order Marker) handling for Wrangler config files to resolve parsing errors when config files contain BOMs.
Changes
Core Implementation:
readFileSync
inparse.ts
to read files as binary buffers first, then validate/strip BOMs before parsingremoveBOMAndValidate
function that detects and handles different BOM types:ef bb bf
): Silently removed before parsingParseError
with actionable guidance to save as UTF-8 without BOMError Handling:
ParseError
instances directly, preserving detailed BOM error messagesTest Coverage:
Key Review Points
Testing
All BOM handling tests pass, including:
Link to Devin run: https://app.devin.ai/sessions/d8d27611f75e4c97b1be565945f1588c
Requested by: @petebacondarwin