Repository navigation
fix(truncatewords): ignore leading whitespace when counting words - #954
Merged
harttle merged 1 commit intoSep 20, 2026
Merged
Conversation
str.split(/\s+/) yields a leading empty element when the input starts with whitespace, so that element was counted as a word and joined back into the output: " Ground control to Major Tom." truncated to 3 words returned " Ground control..." instead of "Ground control to...". Ruby Liquid splits in awk mode, which discards leading whitespace but keeps trailing whitespace, so trimStart matches it and trim would not.
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Owner
|
@all-contributors please add @youdie006 for code |
Contributor
|
I've put up a pull request to add @youdie006! 🎉 |
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))
|
🎉 This PR is included in version 10.30.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
truncatewordsdoesstr.split(/\s+/)(src/filters/string.ts:183). When the input starts with whitespace that yields a leading''element, which gets counted as a word and joined back into the output:So the result is one word short and carries a stray leading space. This shows up on CMS/HTML-derived text and
{% capture %}output, which routinely start with whitespace.trimStartrather thantrim, because Ruby's awk-modesplit(" ", n+1)discards leading whitespace but leaves trailing whitespace alone -{{ "1 2 3 " | truncatewords: 5 }}returns"1 2 3 "in Ruby, andtrimwould drop that space. Both test rows below cover that.number_of_wordsis unaffected: it already calls.trim()atstring.ts:199before splitting.Verification
Oracle measured against the
liquidgem 5.13.0 onruby:3.3:" Ground control to Major Tom.""Ground control to..."" Ground control...""\t one two three four""one two..."" one...""1 2 3 ""1 2 3 ""1 2 3 "TZ=Asia/Shanghai npm test(the commandtest.ymlruns): 89 suites, 1644 tests, all passing.npm run lintexit 0.Reverting the one-line change fails the first new test (
Expected: "Ground control to..." / Received: " Ground control..."); usingtrim()instead oftrimStart()fails the second (Expected: "1 2 3 " / Received: "1 2 3").I left the existing
{{ "1 2 3" | truncatewords: 3 }}->'1 2 3...'row alone; Ruby returns"1 2 3"there, but that ellipsis policy is pinned by your own test and is a separate question from this one.I used Claude Code while working on this; the change and the tests are mine and I have been through them.