Skip to content

fix(split): split on any whitespace for a single space, like Ruby - #992

Merged
harttle merged 2 commits into
harttle:masterfrom
jayhemnani9910:fix/split-single-space-whitespace
Nov 21, 2026
Merged

harttle merged 2 commits into
harttle:masterfrom
jayhemnani9910:fix/split-single-space-whitespace

Conversation

@jayhemnani9910

Copy link
Copy Markdown
Contributor

split already follows Ruby's String#split by dropping trailing empty strings, but Ruby treats a single-space separator specially: it splits on runs of any whitespace and ignores leading whitespace. liquidjs splits on the literal space, so tabs and newlines stay inside the items and repeated spaces give empty items:

{{ "  one  two
three " | split: " " | join: "|" }}

Shopify Liquid gives one|two|three; liquidjs gives ||one||two\nthree. The common {{ content | split: " " | size }} word count is off for any text with double spaces or line breaks.

With a single space as the separator, split now trims the string and splits on /\s+/ (an all-whitespace string gives an empty array, as in Ruby). Every other separator works as before.

Tests: new case in test/integration/filters/string.spec.ts, which fails without the change. npm run build && npx jest: 1751 passed. eslint is clean.

Comment thread src/filters/string.ts Resolved
@jayhemnani9910
jayhemnani9910 force-pushed the fix/split-single-space-whitespace branch from 00411ff to 150b3ac Compare November 20, 2026 20:04
@harttle
harttle merged commit 433e737 into harttle:master Nov 21, 2026
13 checks passed
@harttle

harttle commented Nov 21, 2026

Copy link
Copy Markdown
Owner

@all-contributors please add @jayhemnani9910 for code

@allcontributors

Copy link
Copy Markdown
Contributor

@harttle

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

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.

3 participants