Skip to content

fix(base64_encode): encode large input in browser builds - #969

Merged
harttle merged 1 commit into
harttle:masterfrom
josefguenther:fix/base64-encode-large-input
Oct 1, 2026
Merged

harttle merged 1 commit into
harttle:masterfrom
josefguenther:fix/base64-encode-large-input

Conversation

@josefguenther

Copy link
Copy Markdown
Contributor

The browser base64Encode (src/build/base64-impl-browser.ts:2) spreads every UTF-8 byte of its input into one String.fromCharCode call, one argument per byte, so base64_encode throws once the input passes the engine's argument limit. {{ v | base64_encode }} with v = "x".repeat(size), through dist/liquid.browser.mjs and dist/liquid.browser.umd.js (same result in both):

size master this PR
100 KB ok ok
125 KB RangeError: Maximum call stack size exceeded ok
1 MB RangeError: Maximum call stack size exceeded ok
5 MB RangeError: Maximum call stack size exceeded ok

"ok" means the output matches Buffer.from(v).toString('base64'). That's V8; engines that cap arguments at 65535, such as QuickJS, fail from 64 KB.

This converts the bytes in 32 KB chunks. The node build, which encodes with Buffer, and base64Decode are unchanged.

The new test in src/build/base64-impl-browser.spec.ts fails on master and passes here. Its input mixes ASCII and a 4-byte character so that a chunk boundary falls inside a character. npm run build, npm test (1673 tests) and npm run lint pass on Node 24.11.1.

Fixes #967

Written with AI assistance (Claude Code); I have reviewed the change.

The browser base64Encode spread every UTF-8 byte of its input into a
single String.fromCharCode call, one argument per byte, so input past
the engine's argument limit threw: past ~125 KB on V8 ("Maximum call
stack size exceeded") and past 64 KB on engines that cap arguments at
65535, such as QuickJS. It now converts the bytes in 32 KB chunks. The
node build, which encodes with Buffer, is unchanged.

Fixes harttle#967

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@harttle
harttle merged commit 8aace78 into harttle:master Oct 1, 2026
14 checks passed
@harttle

harttle commented Oct 1, 2026

Copy link
Copy Markdown
Owner

@all-contributors please add @josefguenther for code

@allcontributors

Copy link
Copy Markdown
Contributor

@harttle

I've put up a pull request to add @josefguenther! 🎉

github-actions Bot pushed a commit that referenced this pull request Oct 1, 2026
# [10.30.0](v10.29.0...v10.30.0) (2026-10-01)

### Bug Fixes

* **base64_encode:** encode large input in browser builds ([#969](#969)) ([8aace78](8aace78)), closes [#967](#967)
* **date:** compute %C and %y from the numeric year ([#961](#961)) ([e68514f](e68514f))
* **date:** compute %U and %W week numbers like strftime ([#958](#958)) ([0587ca8](0587ca8))
* trim custom characters by Unicode code point ([#955](#955)) ([3fe244f](3fe244f))
* **truncatewords:** ignore leading whitespace when counting words ([#954](#954)) ([65e200e](65e200e))
* **url_decode:** keep %2B as a literal plus when decoding ([#939](#939)) ([9af92f5](9af92f5))

### Features

* await promises returned by Drop.valueOf() ([#948](#948)) ([#953](#953)) ([#959](#959)) ([7dfa76b](7dfa76b))
@github-actions

github-actions Bot commented Oct 1, 2026

Copy link
Copy Markdown

🎉 This PR is included in version 10.30.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

base64_encode throws on large input in browser builds

2 participants