Skip to content

fix(emotion): use Buffer.from for base64 encoding in source maps#33

Open
giggo1604 wants to merge 1 commit intorolldown:mainfrom
giggo1604:fix/emotion-sourcemap-btoa-unicode
Open

fix(emotion): use Buffer.from for base64 encoding in source maps#33
giggo1604 wants to merge 1 commit intorolldown:mainfrom
giggo1604:fix/emotion-sourcemap-btoa-unicode

Conversation

@giggo1604
Copy link

@giggo1604 giggo1604 commented Mar 18, 2026

Node's btoa() only accepts Latin-1 characters (U+0000-U+00FF). When source files contain characters outside that range (em dashes, arrows, emoji, etc.), the JSON-stringified source map includes them via the sourceContent field, causing btoa() to throw "InvalidCharacterError: Invalid character".

Replace btoa() with Buffer.from().toString('base64') which handles all Unicode correctly.

Also adds a test for createSourceMap with non-Latin-1 characters."

…ode's btoa() only accepts Latin-1 characters (U+0000-U+00FF).\nWhen source files contain characters outside that range (em dashes,\narrows, emoji, etc.), the JSON-stringified source map includes them\nvia the sourceContent field, causing btoa() to throw\n\"InvalidCharacterError: Invalid character\".\n\nReplace btoa() with Buffer.from().toString('base64') which handles\nall Unicode correctly.\n\nAlso adds a regression test for createSourceMap with non-Latin-1\ncharacters."
@giggo1604 giggo1604 changed the title fix(emotion): use Buffer.from for base64 encoding in source maps\n\nN… fix(emotion): use Buffer.from for base64 encoding in source maps Mar 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant