Skip to content

Commit

Permalink
Fix checking equality against position captures
Browse files Browse the repository at this point in the history
  • Loading branch information
SquidDev committed Nov 7, 2023
1 parent dc245ed commit e734563
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/main/java/org/squiddev/cobalt/lib/StringMatch.java
Original file line number Diff line number Diff line change
Expand Up @@ -673,7 +673,7 @@ int end_capture(int soff, int poff) throws LuaError {
int match_capture(int soff, int l) throws LuaError {
l = check_capture(l);
int len = clen[l];
if ((s.length() - soff) >= len &&
if (len >= 0 && (s.length() - soff) >= len &&
LuaString.equals(s, cinit[l], s, soff, len)) {
return soff + len;
} else {
Expand Down
4 changes: 4 additions & 0 deletions src/test/resources/spec/string_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,10 @@ describe("The string library", function()
expect(result):eq("HELLO WORLD")
expect(count):eq(10)
end)

it("no out-of-bounds with () (issue #78)", function()
string.gsub("foo", "()(%1)", "")
end)
end)

describe("string.len", function()
Expand Down

0 comments on commit e734563

Please sign in to comment.