Skip to content

fix(array_to_sentence_string): coerce non-array input with toArray, fixes #964 - #968

Merged
harttle merged 2 commits into
harttle:masterfrom
josefguenther:fix/array-to-sentence-string-input
Oct 28, 2026
Merged

harttle merged 2 commits into
harttle:masterfrom
josefguenther:fix/array-to-sentence-string-input

Conversation

@josefguenther

@josefguenther josefguenther commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

array_to_sentence_string reads .length and .slice on its input directly (src/filters/string.ts:226), so anything that isn't an array fails the whole render. {{ v | array_to_sentence_string }}:

v master this PR
nil RenderError: Cannot read properties of undefined (reading 'length') ``
5 RenderError: array.slice is not a function 5
"abc" RenderError: array.slice(...).join is not a function abc
"ab" a and b ab
["a", "b", "c"] a, b, and c same

This coerces the input with toArray, as the other array filters do, so nil renders an empty string and a non-array value is treated as a single item. Array input is unchanged.

The two new tests in test/integration/filters/string.spec.ts fail on master and pass here. npm run build, npm test (1674 tests) and npm run lint pass on Node 24.11.1.

Fixes #964

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

array_to_sentence_string read `.length` and `.slice` on its input
directly, so a nil value, a number or a string of three or more
characters threw a RenderError and failed the whole render, and a one-
or two-character string was split into characters. It now coerces its
input with `toArray`, as the other array filters do: nil renders an
empty string and a non-array value is treated as a single item.

Fixes harttle#964

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@harttle

harttle commented Oct 1, 2026

Copy link
Copy Markdown
Owner

This filter comes from Jekyll and I find Jekyll also throws for these cases thus it should be left that way. Unless you find otherwise, I'm closing this one.

@harttle harttle closed this Oct 1, 2026
@josefguenther

Copy link
Copy Markdown
Contributor Author

Thanks for checking. Jekyll's version just calls .length without a check, so I read its throw as a missing guard rather than a choice, and LiquidJS doesn't follow Jekyll there in its other Jekyll filters:

  • number_of_words has the same unguarded input.split in Jekyll and raises on nil or a number, while LiquidJS renders 0 and 1.
  • slugify and cgi_escape raise on a number in Jekyll (cgi_escape on nil too), while LiquidJS renders it as text.
  • date_to_string, date_to_long_string, date_to_rfc822 and date_to_xmlschema raise InvalidDateError in Jekyll on a string that isn't a date, while LiquidJS renders the input as written.
  • group_by and find raise in Jekyll on an array holding items that aren't hashes, while LiquidJS returns a result.

Of the 24 Jekyll filters LiquidJS ports, array_to_sentence_string is the only one that throws on ordinary non-array input. Jekyll also renders with render! at build time, where a raise stops the author's build rather than a page someone is viewing. So I'd still suggest toArray here, as LiquidJS's other ported Jekyll and array filters do, but it's your call.

@harttle

harttle commented Oct 28, 2026

Copy link
Copy Markdown
Owner

Makes sense. Will handle the render!, render inconsistency latter, for now this PR is good enough to merge.

@harttle harttle reopened this Oct 28, 2026
@harttle harttle changed the title fix(array_to_sentence_string): coerce non-array input with toArray fix(array_to_sentence_string): coerce non-array input with toArray, fixes #964 Oct 28, 2026
@harttle
harttle merged commit e843466 into harttle:master Oct 28, 2026
14 checks passed
github-actions Bot pushed a commit that referenced this pull request Oct 28, 2026
## [10.30.1](v10.30.0...v10.30.1) (2026-10-28)

### Bug Fixes

* apply outputEscape to {% echo %} ([46ab5d8](46ab5d8))
* **array_to_sentence_string:** coerce non-array input with toArray ([#968](#968)) ([e843466](e843466)), closes [#964](#964)
* **base64_decode:** throw on invalid input in every build ([#971](#971)) ([83bbfe0](83bbfe0)), closes [#965](#965)
* **date_to_rfc822:** use English day and month names ([#974](#974)) ([e94a1c4](e94a1c4)), closes [#973](#973)
* **filters:** round must not alter large or high-precision numbers ([#980](#980)) ([ea22af4](ea22af4)), closes [hi#precision](https://github.com/hi/issues/precision)
* **filters:** truncate and slice must not split surrogate pairs ([#981](#981)) ([57016eb](57016eb)), closes [String#length](https://github.com/String/issues/length) [String#slice](https://github.com/String/issues/slice)
* pad %Y to 4 digits like Ruby ([#978](#978)) ([95a2eed](95a2eed))
* **security:** apply outputEscape to {% cycle %} ([#984](#984)) ([2e1ebe0](2e1ebe0))
@github-actions

Copy link
Copy Markdown

🎉 This PR is included in version 10.30.1 🎉

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

array_to_sentence_string throws on nil, number and string input

2 participants