Skip to content

Commit

Permalink
fix(stringx) strip using wrong index if # > 200
Browse files Browse the repository at this point in the history
  • Loading branch information
Tieske committed May 18, 2021
1 parent 10dfaea commit 19c863e
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 3 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ deprecation policy.

see [CONTRIBUTING.md](CONTRIBUTING.md#release-instructions-for-a-new-version) for release instructions

## 1.10.x unreleased
- fix: `stringx.strip` behaved badly with string lengths > 200
[#382](https://github.com/lunarmodules/Penlight/pull/382)


## 1.10.0 (2021-04-27)

- deprecate: `permute.iter`, renamed to `permute.order_iter` (removal later)
Expand Down
2 changes: 1 addition & 1 deletion lua/pl/stringx.lua
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ local function _strip(s,left,right,chrs)
local rs = reverse(s)
local i1,i2 = find(rs, '^'..chrs..'*')
if i2 >= i1 then
t = -i2
t = -i2-1
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lua/pl/types.lua
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ end
-- An object is considered empty if it is:
--
-- - `nil`
-- - a table with out any items (key-value pairs or indexes)
-- - a table without any items (key-value pairs or indexes)
-- - a string with no content ("")
-- - not a nil/table/string
-- @param o The object to check if it is empty.
Expand Down
3 changes: 2 additions & 1 deletion tests/test-stringx.lua
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,7 @@ asserteq(T(stringx.shorten('abcde', 0, true)), T'')
asserteq(stringx.strip(' hello '),'hello')
asserteq(stringx.strip('--[hello] -- - ','-[] '),'hello')
asserteq(stringx.rstrip('--[hello] -- - ','-[] '),'--[hello')
asserteq(stringx.strip('hello'..((" "):rep(500))), "hello")

--

Expand All @@ -332,7 +333,7 @@ local assert_str_round_trip = function(s)
end

if compiled ~= s then
print("strinx.quote_string assert Failed: String compiled but did not round trip.")
print("stringx.quote_string assert Failed: String compiled but did not round trip.")
print("input string:\t\t",s, #s)
print("compiled string:\t", compiled, #compiled)
print("output string:\t\t",qs, #qs)
Expand Down

0 comments on commit 19c863e

Please sign in to comment.