logoalt Hacker News

danhau11/29/20253 repliesview on HN

> However, when decoding, we must handle errors and skip spaces.

This had me scratching my head. Why would a base64 decoder need to skip spaces? But indeed, MDN documents this behavior:

> Note that: The whitespace in the space is ignored.

JS never ceases to surprise. Also, check out that typo :D

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...


Replies

wvbdmptoday at 12:32 AM

Probably so you can put in line breaks? Seems common in base64 data, such as armored PGP keys or emails attachments. HTML attributes allow line breaks, although I haven’t seen it done for base64 images.

layer8today at 1:23 AM

This might be for compatibility with XML Schema base64Binary, which collapses all whitespace (such as line breaks) to single spaces.

cluckindan11/29/2025

So technically it’s now possible to hide a payload in somewhat human-readable text, as long as it base64-decodes.

show 2 replies