summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoritchyny <itchyny@cybozu.co.jp>2023-07-09 15:25:21 +0900
committerNico Williams <nico@cryptonector.com>2023-07-09 12:51:53 -0500
commit600e602548216c6d0cfb3254202a690862901e4c (patch)
treeb3b88f40cef5a92ba3ca24f0e6e30773e0be8490
parentcac216a39c120166b247b5dc8f0ded56b4bb3281 (diff)
Fix empty regular expression matches (fix #2565)
-rw-r--r--src/builtin.c2
-rw-r--r--tests/onig.test24
2 files changed, 14 insertions, 12 deletions
diff --git a/src/builtin.c b/src/builtin.c
index 0fd75543..3cde6866 100644
--- a/src/builtin.c
+++ b/src/builtin.c
@@ -1002,7 +1002,7 @@ static jv f_match(jq_state *jq, jv input, jv regex, jv modifiers, jv testmode) {
jv_string((char*)ebuf)));
break;
}
- } while (global && start != end);
+ } while (global && start <= end);
onig_region_free(region,1);
region = NULL;
if (region)
diff --git a/tests/onig.test b/tests/onig.test
index d49391fc..3edb07df 100644
--- a/tests/onig.test
+++ b/tests/onig.test
@@ -1,12 +1,16 @@
# match builtin
[match("( )*"; "g")]
"abc"
-[{"offset":0, "length":0, "string":"", "captures":[]},{"offset":1, "length":0, "string":"", "captures":[]},{"offset":2, "length":0, "string":"", "captures":[]}]
+[{"offset":0, "length":0, "string":"", "captures":[]}, {"offset":1, "length":0, "string":"", "captures":[]}, {"offset":2, "length":0, "string":"", "captures":[]}, {"offset":3, "length":0, "string":"", "captures":[]}]
[match("( )*"; "gn")]
"abc"
[]
+[match(""; "g")]
+"ab"
+[{"offset":0,"length":0,"string":"","captures":[]},{"offset":1,"length":0,"string":"","captures":[]},{"offset":2,"length":0,"string":"","captures":[]}]
+
[match("a"; "gi")]
"āáàä"
[]
@@ -71,29 +75,27 @@ gsub("a";"b")
"aaaaa"
"bbbbb"
-gsub( "(.*)"; ""; "x")
+gsub("(.*)"; ""; "x")
""
""
-gsub( ""; "a"; "g")
+gsub(""; "a"; "g")
""
"a"
-gsub( "^"; ""; "g")
+gsub("^"; ""; "g")
"a"
"a"
-
-# The following is a regression test and should not be construed as a requirement other than that execution should terminate:
-gsub( ""; "a"; "g")
+gsub(""; "a"; "g")
"a"
-"aa"
+"aaa"
-gsub( "$"; "a"; "g")
+gsub("$"; "a"; "g")
"a"
"aa"
-gsub( "^"; "a")
+gsub("^"; "a")
""
"a"
@@ -163,5 +165,5 @@ sub("(?<x>.)"; "\(.x)!")
# splits and _nwise
[splits("")]
"ab"
-["","a","b"]
+["","a","b",""]