Why Base64 Encoding Unicode Names Fails in Python, Node and the Browser
A developer building an email verification link found that a username with accented and Chinese characters produced garbled output and errors. The core issue is that Base64 operates only on bytes, so the string must first be converted using an explicit encoding such as UTF-8. Python 3.11 refuses to encode a str directly and forces the developer to choose an encoding, while Node 22's Buffer defaults to UTF-8 and yields identical results. The browser's btoa() function throws an InvalidCharacterError for characters outside the Latin-1 range, so UTF-8 bytes must be prepared before encoding. The article concludes that explicit UTF-8 handling on both ends keeps tokens portable across languages.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.
Discussion (0)
Log in to join the discussion and vote.
Log in