Skip to content

Commit

Permalink
Allow updating PCRE2_EXRA_ASCII_DIGIT by (?aP)
Browse files Browse the repository at this point in the history
For consistency with PCRE2_EXTRA_ASCII_POSIX, allow the inline use
of (?a) to affect the definition for [:sigit:] and [:xdigit:]
  • Loading branch information
carenas committed Oct 8, 2023
1 parent cecb429 commit 25e69a5
Show file tree
Hide file tree
Showing 5 changed files with 220 additions and 13 deletions.
7 changes: 4 additions & 3 deletions src/pcre2_compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -2741,7 +2741,7 @@ the main compiling phase. */

#define PARSE_TRACKED_EXTRA_OPTIONS (PCRE2_EXTRA_CASELESS_RESTRICT| \
PCRE2_EXTRA_ASCII_BSD|PCRE2_EXTRA_ASCII_BSS|PCRE2_EXTRA_ASCII_BSW| \
PCRE2_EXTRA_ASCII_POSIX)
PCRE2_EXTRA_ASCII_DIGIT|PCRE2_EXTRA_ASCII_POSIX)

/* States used for analyzing ranges in character classes. The two OK values
must be last. */
Expand Down Expand Up @@ -4233,7 +4233,7 @@ while (ptr < ptrend)
}
if (*ptr == CHAR_P)
{
*xoptset |= PCRE2_EXTRA_ASCII_POSIX;
*xoptset |= (PCRE2_EXTRA_ASCII_DIGIT|PCRE2_EXTRA_ASCII_POSIX);
ptr++;
break;
}
Expand All @@ -4251,7 +4251,8 @@ while (ptr < ptrend)
}
}
*xoptset |= PCRE2_EXTRA_ASCII_BSD|PCRE2_EXTRA_ASCII_BSS|
PCRE2_EXTRA_ASCII_BSW|PCRE2_EXTRA_ASCII_POSIX;
PCRE2_EXTRA_ASCII_BSW|
PCRE2_EXTRA_ASCII_DIGIT|PCRE2_EXTRA_ASCII_POSIX;
break;

case CHAR_J: /* Record that it changed in the external options */
Expand Down
45 changes: 43 additions & 2 deletions testdata/testinput5
Original file line number Diff line number Diff line change
Expand Up @@ -2343,11 +2343,19 @@
\= Expect no match
\x{660}\x{660}\x{660}

/\d(?-aD)\d(?aD)\d/utf,ucp,ascii_bsd
999
9\x{660}9

/\d(?a)\d(?-a)\d/utf,ucp
\x{660}9\x{660}
\= Expect no match
\x{660}\x{660}\x{660}

/\d(?-aD)\d(?aD)\d/utf,ucp,ascii_bsd
999
9\x{660}9

# SPACES

/>\s+</i,utf
Expand Down Expand Up @@ -2435,18 +2443,51 @@

# POSIX

/[[:digit:]]+/utf,ucp
/^[[:digit:]]+$/utf,ucp
123456
123\x{660}456

/[[:digit:]]+/utf,ucp,ascii_digit
/^[[:digit:]]+$/utf,ucp,ascii_digit
123456
\= Expect no match
123\x{660}456

/[[:digit:]]+/g,utf,ucp,ascii_digit
123\x{660}456

/(?-aP)[[:digit:]](?aP)[[:digit:]]/utf,ucp,ascii_digit
11
\x{ff11}1
\= Expect no match
1\x{ff11}

/(?-aP:[[:digit:]])[[:digit:]]/utf,ucp,ascii_digit
11
\x{ff11}1
\= Expect no match
1\x{ff11}

/(?-aP:[[:digit:]])[[:digit:]]/utf,never_ucp,ascii_digit
11
\= Expect no match
\x{ff11}1
1\x{ff11}

/[[:digit:]]+/utf,ucp,ascii_posix
123\x{660}456

/(?-aP)[[:digit:]](?aP)[[:digit:]]/utf,ucp,ascii_posix
11
\x{ff11}1
\= Expect no match
1\x{ff11}

/(?-aP:[[:digit:]])[[:digit:]]/utf,ucp,ascii_posix
11
\x{ff11}1
\= Expect no match
1\x{ff11}

/^[[:xdigit:]]+$/utf,ucp
f0
1A
Expand Down
45 changes: 43 additions & 2 deletions testdata/testinput7
Original file line number Diff line number Diff line change
Expand Up @@ -2355,11 +2355,19 @@
\= Expect no match
\x{660}\x{660}\x{660}

/\d(?-aD)\d(?aD)\d/utf,ucp,ascii_bsd
999
9\x{660}9

/\d(?a)\d(?-a)\d/utf,ucp
\x{660}9\x{660}
\= Expect no match
\x{660}\x{660}\x{660}

/\d(?-aD)\d(?aD)\d/utf,ucp,ascii_bsd
999
9\x{660}9

# SPACES

/>\s+</i,utf
Expand Down Expand Up @@ -2432,18 +2440,51 @@

# POSIX

/[[:digit:]]+/utf,ucp
/^[[:digit:]]+$/utf,ucp
123456
123\x{660}456

/[[:digit:]]+/utf,ucp,ascii_digit
/^[[:digit:]]+$/utf,ucp,ascii_digit
123456
\= Expect no match
123\x{660}456

/[[:digit:]]+/g,utf,ucp,ascii_digit
123\x{660}456

/(?-aP)[[:digit:]](?aP)[[:digit:]]/utf,ucp,ascii_digit
11
\x{ff11}1
\= Expect no match
1\x{ff11}

/(?-aP:[[:digit:]])[[:digit:]]/utf,ucp,ascii_digit
11
\x{ff11}1
\= Expect no match
1\x{ff11}

/(?-aP:[[:digit:]])[[:digit:]]/utf,never_ucp,ascii_digit
11
\= Expect no match
\x{ff11}1
1\x{ff11}

/[[:digit:]]+/utf,ucp,ascii_posix
123\x{660}456

/(?-aP)[[:digit:]](?aP)[[:digit:]]/utf,ucp,ascii_posix
11
\x{ff11}1
\= Expect no match
1\x{ff11}

/(?-aP:[[:digit:]])[[:digit:]]/utf,ucp,ascii_posix
11
\x{ff11}1
\= Expect no match
1\x{ff11}

/>[[:space:]]+</utf,ucp
>\x{a0} \x{a0}<
>\x{a0}\x{a0}\x{a0}<
Expand Down
68 changes: 65 additions & 3 deletions testdata/testoutput5
Original file line number Diff line number Diff line change
Expand Up @@ -5251,13 +5251,25 @@ No match
\x{660}\x{660}\x{660}
No match

/\d(?-aD)\d(?aD)\d/utf,ucp,ascii_bsd
999
0: 999
9\x{660}9
0: 9\x{660}9

/\d(?a)\d(?-a)\d/utf,ucp
\x{660}9\x{660}
0: \x{660}9\x{660}
\= Expect no match
\x{660}\x{660}\x{660}
No match

/\d(?-aD)\d(?aD)\d/utf,ucp,ascii_bsd
999
0: 999
9\x{660}9
0: 9\x{660}9

# SPACES

/>\s+</i,utf
Expand Down Expand Up @@ -5375,23 +5387,73 @@ No match

# POSIX

/[[:digit:]]+/utf,ucp
/^[[:digit:]]+$/utf,ucp
123456
0: 123456
123\x{660}456
0: 123\x{660}456

/[[:digit:]]+/utf,ucp,ascii_digit
/^[[:digit:]]+$/utf,ucp,ascii_digit
123456
0: 123456
\= Expect no match
123\x{660}456
0: 123
No match

/[[:digit:]]+/g,utf,ucp,ascii_digit
123\x{660}456
0: 123
0: 456

/(?-aP)[[:digit:]](?aP)[[:digit:]]/utf,ucp,ascii_digit
11
0: 11
\x{ff11}1
0: \x{ff11}1
\= Expect no match
1\x{ff11}
No match

/(?-aP:[[:digit:]])[[:digit:]]/utf,ucp,ascii_digit
11
0: 11
\x{ff11}1
0: \x{ff11}1
\= Expect no match
1\x{ff11}
No match

/(?-aP:[[:digit:]])[[:digit:]]/utf,never_ucp,ascii_digit
11
0: 11
\= Expect no match
\x{ff11}1
No match
1\x{ff11}
No match

/[[:digit:]]+/utf,ucp,ascii_posix
123\x{660}456
0: 123

/(?-aP)[[:digit:]](?aP)[[:digit:]]/utf,ucp,ascii_posix
11
0: 11
\x{ff11}1
0: \x{ff11}1
\= Expect no match
1\x{ff11}
No match

/(?-aP:[[:digit:]])[[:digit:]]/utf,ucp,ascii_posix
11
0: 11
\x{ff11}1
0: \x{ff11}1
\= Expect no match
1\x{ff11}
No match

/^[[:xdigit:]]+$/utf,ucp
f0
0: f0
Expand Down
68 changes: 65 additions & 3 deletions testdata/testoutput7
Original file line number Diff line number Diff line change
Expand Up @@ -3971,13 +3971,25 @@ No match
\x{660}\x{660}\x{660}
No match

/\d(?-aD)\d(?aD)\d/utf,ucp,ascii_bsd
999
0: 999
9\x{660}9
0: 9\x{660}9

/\d(?a)\d(?-a)\d/utf,ucp
\x{660}9\x{660}
0: \x{660}9\x{660}
\= Expect no match
\x{660}\x{660}\x{660}
No match

/\d(?-aD)\d(?aD)\d/utf,ucp,ascii_bsd
999
0: 999
9\x{660}9
0: 9\x{660}9

# SPACES

/>\s+</i,utf
Expand Down Expand Up @@ -4076,23 +4088,73 @@ No match

# POSIX

/[[:digit:]]+/utf,ucp
/^[[:digit:]]+$/utf,ucp
123456
0: 123456
123\x{660}456
0: 123\x{660}456

/[[:digit:]]+/utf,ucp,ascii_digit
/^[[:digit:]]+$/utf,ucp,ascii_digit
123456
0: 123456
\= Expect no match
123\x{660}456
0: 123
No match

/[[:digit:]]+/g,utf,ucp,ascii_digit
123\x{660}456
0: 123
0: 456

/(?-aP)[[:digit:]](?aP)[[:digit:]]/utf,ucp,ascii_digit
11
0: 11
\x{ff11}1
0: \x{ff11}1
\= Expect no match
1\x{ff11}
No match

/(?-aP:[[:digit:]])[[:digit:]]/utf,ucp,ascii_digit
11
0: 11
\x{ff11}1
0: \x{ff11}1
\= Expect no match
1\x{ff11}
No match

/(?-aP:[[:digit:]])[[:digit:]]/utf,never_ucp,ascii_digit
11
0: 11
\= Expect no match
\x{ff11}1
No match
1\x{ff11}
No match

/[[:digit:]]+/utf,ucp,ascii_posix
123\x{660}456
0: 123

/(?-aP)[[:digit:]](?aP)[[:digit:]]/utf,ucp,ascii_posix
11
0: 11
\x{ff11}1
0: \x{ff11}1
\= Expect no match
1\x{ff11}
No match

/(?-aP:[[:digit:]])[[:digit:]]/utf,ucp,ascii_posix
11
0: 11
\x{ff11}1
0: \x{ff11}1
\= Expect no match
1\x{ff11}
No match

/>[[:space:]]+</utf,ucp
>\x{a0} \x{a0}<
0: >\x{a0} \x{a0}<
Expand Down

0 comments on commit 25e69a5

Please sign in to comment.