truncatewords - truncate indicator is always added, even if shorter
Closed this issue · 10 comments
If i use truncatewords
in one of my OC liquid templates, the 3 dots are always visible, even if the text is much shorter.
This happend to me, when i used it like this truncatewords: 40
, but the 3 dots are also shown on a text with 20 words or something like that.
Changing the indicator to a custom one also doesn't change that behavior.
Let me double check
If you check below everything seems as expected
fluid/Fluid.Tests/StringFiltersTests.cs
Lines 299 to 314 in f61b88f
Could you please break the test to ensure there's a bug
@hishamco I'm not quite sure if i'm missing something here, but your last test in line 303 doesn't make much sense to me or seems wrong.
You truncate to 10 words, the example is way shorter, still you have the dots.
That's pretty much exactly the problem i have.
The text is shorter then the truncate size, but still gets the dots or whatever string will be defined for that.
Also in my tests with the exact same values, the spaces get removed automatically.
As you can see, i also showed the problem with the example in the last line of my tests.
Backend:
OC Version: 1.4.0
The bug is obvious, and we need to check the behavior of when the number of words matches exactly by looking at Shopify 's tests.
Ya, I notice the bug, also I might check with Liquid the case that Seb mentioned
And probably also fix truncate
since it has the same logic:
FYI
{{ "The cat came back the very next day" | truncatewords : 4 }} -> The cat came back...
{{ "The cat came back the very next day" | truncatewords : 8 }} -> The cat came back the very next day...
{{ "The cat came back the very next day" | truncatewords : 12 }} -> The cat came back the very next day
tested in https://liquidjs.com/playground.html
I will push a PR soon ..
@sebastienros I checked truncate
the logic seems right
@hishamco Thanks a lot!