Fix empty regular expression matches (fix #2565)
This commit is contained in:
1 parent
cac216a39c
commit
600e602548
2 files changed
+15
-13
No files matched your search
+1
-1
@@ -1002,7 +1002,7 @@ static jv f_match(jq_state *jq, jv input, jv regex, jv modifiers, jv testmode) {
|
|||||||
jv_string((char*)ebuf)));
|
jv_string((char*)ebuf)));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} while (global && start != end);
|
} while (global && start <= end);
|
||||||
onig_region_free(region,1);
|
onig_region_free(region,1);
|
||||||
region = NULL;
|
region = NULL;
|
||||||
if (region)
|
if (region)
|
||||||
|
|||||||
+14
-12
@@ -1,12 +1,16 @@
|
|||||||
# match builtin
|
# match builtin
|
||||||
[match("( )*"; "g")]
|
[match("( )*"; "g")]
|
||||||
"abc"
|
"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")]
|
[match("( )*"; "gn")]
|
||||||
"abc"
|
"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")]
|
[match("a"; "gi")]
|
||||||
"āáàä"
|
"āáàä"
|
||||||
[]
|
[]
|
||||||
@@ -71,29 +75,27 @@ gsub("a";"b")
|
|||||||
"aaaaa"
|
"aaaaa"
|
||||||
"bbbbb"
|
"bbbbb"
|
||||||
|
|
||||||
gsub( "(.*)"; ""; "x")
|
gsub("(.*)"; ""; "x")
|
||||||
""
|
""
|
||||||
""
|
""
|
||||||
|
|
||||||
gsub( ""; "a"; "g")
|
gsub(""; "a"; "g")
|
||||||
""
|
""
|
||||||
"a"
|
"a"
|
||||||
|
|
||||||
gsub( "^"; ""; "g")
|
gsub("^"; ""; "g")
|
||||||
"a"
|
"a"
|
||||||
"a"
|
"a"
|
||||||
|
|
||||||
|
gsub(""; "a"; "g")
|
||||||
|
"a"
|
||||||
|
"aaa"
|
||||||
|
|
||||||
# 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"
|
"a"
|
||||||
"aa"
|
"aa"
|
||||||
|
|
||||||
gsub( "$"; "a"; "g")
|
gsub("^"; "a")
|
||||||
"a"
|
|
||||||
"aa"
|
|
||||||
|
|
||||||
gsub( "^"; "a")
|
|
||||||
""
|
""
|
||||||
"a"
|
"a"
|
||||||
|
|
||||||
@@ -163,5 +165,5 @@ sub("(?<x>.)"; "\(.x)!")
|
|||||||
# splits and _nwise
|
# splits and _nwise
|
||||||
[splits("")]
|
[splits("")]
|
||||||
"ab"
|
"ab"
|
||||||
["","a","b"]
|
["","a","b",""]
|
||||||
|
|
||||||
Reference in new issue
Block a user