fix(strings): keep last char when truncate separator is absent

str.rfind returns -1 when a string separator is not present in the
truncated text. Using that -1 as a slice end dropped an extra trailing
character before appending the omission. Only adjust the truncation point
when the separator is actually found, matching the regex-separator branch
and lodash behaviour.
This commit is contained in:
dualfroz committed 2026-09-04 09:04:55 +02:00
1 parent 0e75093e29
commit 7fc28b38e1
3 files changed
+90 -1

No files matched your search

+4
View File
@@ -1079,6 +1079,10 @@ def test_trim_end(case, expected):
("hi-diddly-ho there, neighborino", 24, "...", re.compile(",? +")),
"hi-diddly-ho there...",
),
# A string separator that does not occur in the truncated text must not
# trim any additional characters; truncation falls back to the plain cut.
(("hello world", 10, "...", "xyz"), "hello w..."),
(("hello world", 8, "...", "q"), "hello..."),
(("hi-diddly-ho there, neighborino", 30, " [...]"), "hi-diddly-ho there, neig [...]"),
(("123456789", 9), "123456789"),
(("123456789", 8), "12345..."),