Fix string.find (#1390)
This commit is contained in:
@@ -94,7 +94,7 @@ export const stringApi = new LuaTable({
|
||||
const reg = new RegExp(pattern);
|
||||
const index = s.slice(init - 1).search(reg);
|
||||
|
||||
if (index < 0) return;
|
||||
if (index < 0) return null;
|
||||
|
||||
const match = s.slice(init - 1).match(reg);
|
||||
const result = [index + init, index + init + match![0].length - 1];
|
||||
|
||||
@@ -185,3 +185,9 @@ assertEqual(#matches, 3)
|
||||
assertEqual(matches[1][1], "ll")
|
||||
assertEqual(matches[2][1], "lll")
|
||||
assertEqual(matches[3][1], "l")
|
||||
|
||||
-- https://community.silverbullet.md/t/test-if-string-find-outputs-nil-not-working-as-expected/2342
|
||||
assert(string.find("a", "b") == nil)
|
||||
assert(not (string.find("a", "b") ~= nil))
|
||||
assert(string.match("a", "b") == nil)
|
||||
assert(not (string.match("a", "b") ~= nil))
|
||||
|
||||
Reference in New Issue
Block a user