Skip to content

Commit 9d1a620

Browse files
authored
Improve error descriptions for capture lists (#709)
1 parent b79ee1d commit 9d1a620

File tree

5 files changed

+33
-23
lines changed

5 files changed

+33
-23
lines changed

src/pcre2_compile.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2707,7 +2707,7 @@ int i;
27072707

27082708
if (ptr >= ptrend || *ptr != CHAR_LEFT_PARENTHESIS)
27092709
{
2710-
*errorcodeptr = ERR15;
2710+
*errorcodeptr = ERR118;
27112711
goto FAILED;
27122712
}
27132713

@@ -2716,6 +2716,12 @@ for (;;)
27162716
ptr++;
27172717
next_offset = (PCRE2_SIZE)(ptr - cb->start_pattern);
27182718

2719+
if (ptr >= ptrend)
2720+
{
2721+
*errorcodeptr = ERR117;
2722+
goto FAILED;
2723+
}
2724+
27192725
/* Handle [+-]number cases */
27202726
if (read_number(&ptr, ptrend, cb->bracount, MAX_GROUP_NUMBER, ERR61,
27212727
&i, errorcodeptr))
@@ -2732,16 +2738,14 @@ for (;;)
27322738
else if (*errorcodeptr != 0) goto FAILED; /* Number too big */
27332739
else
27342740
{
2735-
if (ptr >= ptrend) goto UNCLOSED_PARENTHESIS;
2736-
27372741
/* Handle 'name' or <name> cases. */
27382742
if (*ptr == CHAR_LESS_THAN_SIGN)
27392743
terminator = CHAR_GREATER_THAN_SIGN;
27402744
else if (*ptr == CHAR_APOSTROPHE)
27412745
terminator = CHAR_APOSTROPHE;
27422746
else
27432747
{
2744-
*errorcodeptr = ERR15;
2748+
*errorcodeptr = ERR117;
27452749
goto FAILED;
27462750
}
27472751

@@ -4767,8 +4771,7 @@ while (ptr < ptrend)
47674771
goto NEGATIVE_LOOK_AHEAD;
47684772

47694773
case META_SCS:
4770-
if (++ptr >= ptrend) goto UNCLOSED_PARENTHESIS;
4771-
4774+
ptr++;
47724775
*parsed_pattern++ = META_SCS;
47734776

47744777
parsed_pattern = parse_capture_list(&ptr, ptrend, utf, parsed_pattern,

src/pcre2_compile.h

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -51,18 +51,18 @@ pcre2.h.in must be updated - their values are exactly 100 greater than these
5151
values. */
5252

5353
enum { ERR0 = COMPILE_ERROR_BASE,
54-
ERR1, ERR2, ERR3, ERR4, ERR5, ERR6, ERR7, ERR8, ERR9, ERR10,
55-
ERR11, ERR12, ERR13, ERR14, ERR15, ERR16, ERR17, ERR18, ERR19, ERR20,
56-
ERR21, ERR22, ERR23, ERR24, ERR25, ERR26, ERR27, ERR28, ERR29, ERR30,
57-
ERR31, ERR32, ERR33, ERR34, ERR35, ERR36, ERR37, ERR38, ERR39, ERR40,
58-
ERR41, ERR42, ERR43, ERR44, ERR45, ERR46, ERR47, ERR48, ERR49, ERR50,
59-
ERR51, ERR52, ERR53, ERR54, ERR55, ERR56, ERR57, ERR58, ERR59, ERR60,
60-
ERR61, ERR62, ERR63, ERR64, ERR65, ERR66, ERR67, ERR68, ERR69, ERR70,
61-
ERR71, ERR72, ERR73, ERR74, ERR75, ERR76, ERR77, ERR78, ERR79, ERR80,
62-
ERR81, ERR82, ERR83, ERR84, ERR85, ERR86, ERR87, ERR88, ERR89, ERR90,
63-
ERR91, ERR92, ERR93, ERR94, ERR95, ERR96, ERR97, ERR98, ERR99, ERR100,
64-
ERR101,ERR102,ERR103,ERR104,ERR105,ERR106,ERR107,ERR108,ERR109,ERR110,
65-
ERR111,ERR112,ERR113,ERR114,ERR115,ERR116 };
54+
ERR1, ERR2, ERR3, ERR4, ERR5, ERR6, ERR7, ERR8, ERR9, ERR10,
55+
ERR11, ERR12, ERR13, ERR14, ERR15, ERR16, ERR17, ERR18, ERR19, ERR20,
56+
ERR21, ERR22, ERR23, ERR24, ERR25, ERR26, ERR27, ERR28, ERR29, ERR30,
57+
ERR31, ERR32, ERR33, ERR34, ERR35, ERR36, ERR37, ERR38, ERR39, ERR40,
58+
ERR41, ERR42, ERR43, ERR44, ERR45, ERR46, ERR47, ERR48, ERR49, ERR50,
59+
ERR51, ERR52, ERR53, ERR54, ERR55, ERR56, ERR57, ERR58, ERR59, ERR60,
60+
ERR61, ERR62, ERR63, ERR64, ERR65, ERR66, ERR67, ERR68, ERR69, ERR70,
61+
ERR71, ERR72, ERR73, ERR74, ERR75, ERR76, ERR77, ERR78, ERR79, ERR80,
62+
ERR81, ERR82, ERR83, ERR84, ERR85, ERR86, ERR87, ERR88, ERR89, ERR90,
63+
ERR91, ERR92, ERR93, ERR94, ERR95, ERR96, ERR97, ERR98, ERR99, ERR100,
64+
ERR101, ERR102, ERR103, ERR104, ERR105, ERR106, ERR107, ERR108, ERR109, ERR110,
65+
ERR111, ERR112, ERR113, ERR114, ERR115, ERR116, ERR117, ERR118 };
6666

6767
/* Code values for parsed patterns, which are stored in a vector of 32-bit
6868
unsigned ints. Values less than META_END are literal data values. The coding

src/pcre2_error.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,8 @@ static const unsigned char compile_error_texts[] =
206206
/* 115 */
207207
"terminating ] with no following closing parenthesis in (?[...]\0"
208208
"unexpected character in (?[...]) extended character class\0"
209+
"expected capture group number or name\0"
210+
"missing opening parenthesis\0"
209211
;
210212

211213
/* Match-time and UTF error texts are in the same format. */

testdata/testinput2

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7838,6 +7838,8 @@ a)"xI
78387838

78397839
/(?1:1/
78407840

7841+
/(?R:(1/
7842+
78417843
/(?R:(1,/
78427844

78437845
/(?R0:(1,2!/

testdata/testoutput2

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18812,10 +18812,10 @@ No match
1881218812
# Parse errors first
1881318813

1881418814
/(*scs:/
18815-
Failed: error 114 at offset 6: missing closing parenthesis
18815+
Failed: error 218 at offset 6: missing opening parenthesis
1881618816

1881718817
/(*scan_substring:(/
18818-
Failed: error 114 at offset 18: missing closing parenthesis
18818+
Failed: error 217 at offset 18: expected capture group number or name
1881918819

1882018820
/(*scs:('name'/
1882118821
Failed: error 114 at offset 13: missing closing parenthesis
@@ -21885,13 +21885,16 @@ Failed: error -69: error performing replacement case transformation
2188521885
# Parse error tests
2188621886

2188721887
/(?1:/
21888-
Failed: error 115 at offset 4: reference to non-existent subpattern
21888+
Failed: error 218 at offset 4: missing opening parenthesis
2188921889

2189021890
/(?1:1/
21891-
Failed: error 115 at offset 4: reference to non-existent subpattern
21891+
Failed: error 218 at offset 4: missing opening parenthesis
21892+
21893+
/(?R:(1/
21894+
Failed: error 114 at offset 6: missing closing parenthesis
2189221895

2189321896
/(?R:(1,/
21894-
Failed: error 114 at offset 7: missing closing parenthesis
21897+
Failed: error 217 at offset 7: expected capture group number or name
2189521898

2189621899
/(?R0:(1,2!/
2189721900
Failed: error 158 at offset 3: (?R (recursive pattern call) must be followed by a closing parenthesis

0 commit comments

Comments
 (0)