From d704ee40c5324e5ff6c08f009a7aaa3b67b71565 Mon Sep 17 00:00:00 2001 From: Nicholas Wilson Date: Fri, 27 Sep 2024 16:31:01 +0100 Subject: [PATCH] Improve error message for \N{name} in character classes (#502) --- src/pcre2_compile.c | 8 ++++++++ testdata/testinput2 | 6 ++++++ testdata/testoutput2 | 9 +++++++++ 3 files changed, 23 insertions(+) diff --git a/src/pcre2_compile.c b/src/pcre2_compile.c index ec4940e63..fd554f1d2 100644 --- a/src/pcre2_compile.c +++ b/src/pcre2_compile.c @@ -1542,6 +1542,14 @@ else if ((i = escapes[c - ESCAPES_FIRST]) != 0) #endif } + /* Give an error in contexts where quantifiers are not allowed + (character classes; substitution strings). */ + + else if (isclassorsub || cb == NULL) + { + *errorcodeptr = ERR37; + } + /* Give an error if what follows is not a quantifier, but don't override an error set by the quantifier reader (e.g. number overflow). */ diff --git a/testdata/testinput2 b/testdata/testinput2 index c6ee980..a33d987 100644 --- a/testdata/testinput2 +++ b/testdata/testinput2 @@ -913,6 +913,12 @@ /\N{25,ab}/ +/[\N]/ + +/[\N{4}]/ + +/[\N{name}]/ + /a{1,3}b/ungreedy ab diff --git a/testdata/testoutput2 b/testdata/testoutput2 index 2f2b3d1..4c07b72 100644 --- a/testdata/testoutput2 +++ b/testdata/testoutput2 @@ -3245,6 +3245,15 @@ Failed: error 137 at offset 2: PCRE2 does not support \F, \L, \l, \N{name}, \U, /\N{25,ab}/ Failed: error 137 at offset 2: PCRE2 does not support \F, \L, \l, \N{name}, \U, or \u +/[\N]/ +Failed: error 171 at offset 3: \N is not supported in a class + +/[\N{4}]/ +Failed: error 137 at offset 3: PCRE2 does not support \F, \L, \l, \N{name}, \U, or \u + +/[\N{name}]/ +Failed: error 137 at offset 3: PCRE2 does not support \F, \L, \l, \N{name}, \U, or \u + /a{1,3}b/ungreedy ab 0: ab