summaryrefslogtreecommitdiff
path: root/backport-Improve-error-message-for-N-name-in-character-classes.patch
blob: 8ad59b9fe2ee40750958295a287d4929e41fb51a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
From d704ee40c5324e5ff6c08f009a7aaa3b67b71565 Mon Sep 17 00:00:00 2001
From: Nicholas Wilson <niwilson@microsoft.com>
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