Advance past the whole codepoint after a zero-width regex match (#3586)
This commit is contained in:
1 parent
dbcaa9d491
commit
f1f39b42e3
2 files changed
+21
-2
No files matched your search
+8
-2
@@ -1086,8 +1086,14 @@ static jv f_match(jq_state *jq, jv input, jv regex, jv modifiers, jv testmode) {
|
|||||||
onig_foreach_name(reg, f_match_name_iter, &captures);
|
onig_foreach_name(reg, f_match_name_iter, &captures);
|
||||||
match = jv_object_set(match, jv_string("captures"), captures);
|
match = jv_object_set(match, jv_string("captures"), captures);
|
||||||
result = jv_array_append(result, match);
|
result = jv_array_append(result, match);
|
||||||
// ensure '"qux" | match("(?=u)"; "g")' matches just once
|
// ensure '"qux" | match("(?=u)"; "g")' matches just once; advance the
|
||||||
start = (const UChar*)(input_string+region->end[0]+1);
|
// search start past the whole codepoint, not a single byte, so we don't
|
||||||
|
// land in the middle of a multibyte character (which would yield a
|
||||||
|
// spurious duplicate match at the same offset).
|
||||||
|
start = (const UChar*)(input_string + region->end[0] +
|
||||||
|
((size_t)region->end[0] < length
|
||||||
|
? jvp_utf8_decode_length(input_string[region->end[0]])
|
||||||
|
: 1));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -11,6 +11,19 @@
|
|||||||
"ab"
|
"ab"
|
||||||
[{"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":[]}]
|
||||||
|
|
||||||
|
# global zero-width matches must not land inside a multibyte character
|
||||||
|
[match(""; "g") | .offset]
|
||||||
|
"aé€🚀b"
|
||||||
|
[0,1,2,3,4,5]
|
||||||
|
|
||||||
|
gsub(""; "-")
|
||||||
|
"aé"
|
||||||
|
"-a-é-"
|
||||||
|
|
||||||
|
[splits("")]
|
||||||
|
"aé"
|
||||||
|
["","a","é",""]
|
||||||
|
|
||||||
[match("a"; "gi")]
|
[match("a"; "gi")]
|
||||||
"āáàä"
|
"āáàä"
|
||||||
[]
|
[]
|
||||||
|
|||||||
Reference in new issue
Block a user