Skip to content

Commit 448ae6a

Browse files
authored
Commit 1: Remove \p{...}/\P{...} named-character-property handling
std::regex ECMAScript mode does not support \p{Name}; \p tokenizes as an identity escape. Remove pStyleNamedCharacterProperty and its call sites; namedCharacterProperty now covers only POSIX brackets ([:name:], [.x.], [=x=]) and namedCharacterPropertyIsInverted keeps only the [[:^name:]] case (fixing the offset from start+3 to start+2 for POSIX). Update RegExpNamedCharacterProperty getName/isInverted docs to describe POSIX brackets. Remove the four \p{...}/\P{...} corpus lines from test.cpp; keep a plain [a-f\d]+ case for the class-with-escape shape. Bundle: github/codeql-action codeql-bundle-v2.26.1 (CodeQL CLI 2.26.1).
1 parent bfa6530 commit 448ae6a

6 files changed

Lines changed: 193 additions & 263 deletions

File tree

cpp/ql/lib/semmle/code/cpp/regex/RegexTreeView.qll

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1192,13 +1192,13 @@ private module Impl implements RegexTreeViewSig {
11921192
override string getAPrimaryQlClass() { result = "RegExpNamedCharacterProperty" }
11931193

11941194
/**
1195-
* Gets the property name. For example, in `\p{Space}`, the result is
1196-
* `"Space"`.
1195+
* Gets the property name. For example, in `[[:digit:]]`, the result is
1196+
* `"digit"`.
11971197
*/
11981198
string getName() { result = re.getCharacterPropertyName(start, end) }
11991199

12001200
/**
1201-
* Holds if the property is inverted. For example, it holds for `\p{^Digit}`,
1201+
* Holds if the property is inverted. For example, it holds for `[[:^digit:]]`,
12021202
* which matches non-digits.
12031203
*/
12041204
predicate isInverted() { re.namedCharacterPropertyIsInverted(start, end) }

cpp/ql/lib/semmle/code/cpp/regex/internal/ParseRegExp.qll

Lines changed: 2 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -282,9 +282,8 @@ class RegExp extends StringLiteral {
282282
)
283283
}
284284

285-
/** Matches named character properties such as `\p{Word}` and `[[:digit:]]` */
285+
/** Matches named character properties such as `[[:digit:]]`, `[.a.]`, and `[=a=]`. */
286286
predicate namedCharacterProperty(int start, int end, string name) {
287-
this.pStyleNamedCharacterProperty(start, end, name) or
288287
this.posixStyleNamedCharacterProperty(start, end, name) or
289288
this.posixCollatingSymbol(start, end, name) or
290289
this.posixEquivalenceClass(start, end, name)
@@ -367,52 +366,16 @@ class RegExp extends StringLiteral {
367366
name = this.getText().substring(start + 2, end - 2)
368367
}
369368

370-
/**
371-
* Matches named character properties. For example:
372-
* - `\p{Space}`
373-
* - `\P{Digit}` upper-case P means inverted
374-
* - `\p{^Word}` caret also means inverted
375-
*
376-
* These can occur both inside and outside of character classes.
377-
*/
378-
private predicate pStyleNamedCharacterProperty(int start, int end, string name) {
379-
this.escapingChar(start) and
380-
this.getChar(start + 1) in ["p", "P"] and
381-
this.getChar(start + 2) = "{" and
382-
this.getChar(end - 1) = "}" and
383-
end > start and
384-
not exists(int i | start + 2 < i and i < end - 1 | this.getChar(i) = "}") and
385-
exists(int nameStart |
386-
this.getChar(start + 3) = "^" and nameStart = start + 4
387-
or
388-
not this.getChar(start + 3) = "^" and nameStart = start + 3
389-
|
390-
name = this.getText().substring(nameStart, end - 1)
391-
)
392-
}
393-
394369
/**
395370
* Holds if the named character property is inverted. Examples for which it holds:
396-
* - `\P{Digit}` upper-case P means inverted
397-
* - `\p{^Word}` caret also means inverted
398371
* - `[[:^digit:]]`
399372
*
400373
* Examples for which it doesn't hold:
401-
* - `\p{Word}`
402-
* - `\P{^Space}` - upper-case P and caret cancel each other out
403374
* - `[[:alnum:]]`
404375
*/
405376
predicate namedCharacterPropertyIsInverted(int start, int end) {
406-
this.pStyleNamedCharacterProperty(start, end, _) and
407-
exists(boolean upperP, boolean caret |
408-
(if this.getChar(start + 1) = "P" then upperP = true else upperP = false) and
409-
(if this.getChar(start + 3) = "^" then caret = true else caret = false)
410-
|
411-
upperP.booleanXor(caret) = true
412-
)
413-
or
414377
this.posixStyleNamedCharacterProperty(start, end, _) and
415-
this.getChar(start + 3) = "^"
378+
this.getChar(start + 2) = "^"
416379
}
417380

418381
/**
@@ -424,7 +387,6 @@ class RegExp extends StringLiteral {
424387
this.escapingChar(start) and
425388
not this.numberedBackreference(start, _, _) and
426389
not this.namedBackreference(start, _, _) and
427-
not this.pStyleNamedCharacterProperty(start, _, _) and
428390
(
429391
// hex char \xhh
430392
this.getChar(start + 1) = "x" and end = start + 4
@@ -502,9 +464,6 @@ class RegExp extends StringLiteral {
502464
) and
503465
not exists(int x, int y | this.groupStart(x, y) and x <= start and y >= end) and
504466
not exists(int x, int y | this.backreference(x, y) and x <= start and y >= end) and
505-
not exists(int x, int y |
506-
this.pStyleNamedCharacterProperty(x, y, _) and x <= start and y >= end
507-
) and
508467
not exists(int x, int y | this.multiples(x, y, _, _) and x <= start and y >= end)
509468
}
510469

@@ -831,8 +790,6 @@ class RegExp extends StringLiteral {
831790
this.charSet(start, end)
832791
or
833792
this.backreference(start, end)
834-
or
835-
this.pStyleNamedCharacterProperty(start, end, _)
836793
}
837794

838795
private predicate qualifier(int start, int end, boolean maybeEmpty, boolean mayRepeatForever) {
Lines changed: 36 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,36 @@
1-
| test.cpp:144:23:144:23 | a | 22 | 0 | 1 | 23 | 23 |
2-
| test.cpp:144:23:144:24 | a+ | 22 | 0 | 2 | 23 | 24 |
3-
| test.cpp:144:23:144:25 | a+b | 22 | 0 | 3 | 23 | 25 |
4-
| test.cpp:144:25:144:25 | b | 22 | 2 | 3 | 25 | 25 |
5-
| test.cpp:147:23:147:23 | a | 20 | 0 | 1 | 23 | 23 |
6-
| test.cpp:147:23:147:24 | a+ | 20 | 0 | 2 | 23 | 24 |
7-
| test.cpp:147:23:147:25 | a+b | 20 | 0 | 3 | 23 | 25 |
8-
| test.cpp:147:25:147:25 | b | 20 | 2 | 3 | 25 | 25 |
9-
| test.cpp:150:24:150:25 | \\s | 21 | 0 | 2 | 24 | 25 |
10-
| test.cpp:150:24:150:26 | \\s+ | 21 | 0 | 3 | 24 | 26 |
11-
| test.cpp:150:24:150:27 | \\s+$ | 21 | 0 | 4 | 24 | 27 |
12-
| test.cpp:150:27:150:27 | $ | 21 | 3 | 4 | 27 | 27 |
13-
| test.cpp:153:24:153:25 | \\( | 21 | 0 | 2 | 24 | 25 |
14-
| test.cpp:153:24:153:37 | \\(([,\\w]+)+\\)$ | 21 | 0 | 14 | 24 | 37 |
15-
| test.cpp:153:26:153:33 | ([,\\w]+) | 21 | 2 | 10 | 26 | 33 |
16-
| test.cpp:153:26:153:34 | ([,\\w]+)+ | 21 | 2 | 11 | 26 | 34 |
17-
| test.cpp:153:27:153:31 | [,\\w] | 21 | 3 | 8 | 27 | 31 |
18-
| test.cpp:153:27:153:32 | [,\\w]+ | 21 | 3 | 9 | 27 | 32 |
19-
| test.cpp:153:28:153:28 | , | 21 | 4 | 5 | 28 | 28 |
20-
| test.cpp:153:29:153:30 | \\w | 21 | 5 | 7 | 29 | 30 |
21-
| test.cpp:153:35:153:36 | \\) | 21 | 11 | 13 | 35 | 36 |
22-
| test.cpp:153:37:153:37 | $ | 21 | 13 | 14 | 37 | 37 |
23-
| test.cpp:156:25:156:25 | a | 21 | 0 | 1 | 25 | 25 |
24-
| test.cpp:156:25:156:26 | a+ | 21 | 0 | 2 | 25 | 26 |
25-
| test.cpp:156:25:156:27 | a+b | 21 | 0 | 3 | 25 | 27 |
26-
| test.cpp:156:27:156:27 | b | 21 | 2 | 3 | 27 | 27 |
27-
| test.cpp:159:24:159:24 | a | 22 | 0 | 1 | 24 | 24 |
28-
| test.cpp:159:24:159:25 | a+ | 22 | 0 | 2 | 24 | 25 |
29-
| test.cpp:159:24:159:26 | a+b | 22 | 0 | 3 | 24 | 26 |
30-
| test.cpp:159:26:159:26 | b | 22 | 2 | 3 | 26 | 26 |
31-
| test.cpp:162:30:162:30 | a | 26 | 0 | 1 | 30 | 30 |
32-
| test.cpp:162:30:162:31 | a+ | 26 | 0 | 2 | 30 | 31 |
33-
| test.cpp:162:30:162:32 | a+b | 26 | 0 | 3 | 30 | 32 |
34-
| test.cpp:162:32:162:32 | b | 26 | 2 | 3 | 32 | 32 |
35-
| test.cpp:166:22:166:23 | \\s | 21 | 0 | 2 | 22 | 23 |
36-
| test.cpp:166:22:166:24 | \\s+ | 21 | 0 | 3 | 22 | 24 |
37-
| test.cpp:169:22:169:22 | a | 21 | 0 | 1 | 22 | 22 |
38-
| test.cpp:169:22:169:25 | a\\.b | 21 | 0 | 4 | 22 | 25 |
39-
| test.cpp:169:23:169:24 | \\. | 21 | 1 | 3 | 23 | 24 |
40-
| test.cpp:169:25:169:25 | b | 21 | 3 | 4 | 25 | 25 |
1+
| test.cpp:144:23:144:23 | a | 20 | 0 | 1 | 23 | 23 |
2+
| test.cpp:144:23:144:24 | a+ | 20 | 0 | 2 | 23 | 24 |
3+
| test.cpp:144:23:144:25 | a+b | 20 | 0 | 3 | 23 | 25 |
4+
| test.cpp:144:25:144:25 | b | 20 | 2 | 3 | 25 | 25 |
5+
| test.cpp:147:24:147:25 | \\s | 21 | 0 | 2 | 24 | 25 |
6+
| test.cpp:147:24:147:26 | \\s+ | 21 | 0 | 3 | 24 | 26 |
7+
| test.cpp:147:24:147:27 | \\s+$ | 21 | 0 | 4 | 24 | 27 |
8+
| test.cpp:147:27:147:27 | $ | 21 | 3 | 4 | 27 | 27 |
9+
| test.cpp:150:24:150:25 | \\( | 21 | 0 | 2 | 24 | 25 |
10+
| test.cpp:150:24:150:37 | \\(([,\\w]+)+\\)$ | 21 | 0 | 14 | 24 | 37 |
11+
| test.cpp:150:26:150:33 | ([,\\w]+) | 21 | 2 | 10 | 26 | 33 |
12+
| test.cpp:150:26:150:34 | ([,\\w]+)+ | 21 | 2 | 11 | 26 | 34 |
13+
| test.cpp:150:27:150:31 | [,\\w] | 21 | 3 | 8 | 27 | 31 |
14+
| test.cpp:150:27:150:32 | [,\\w]+ | 21 | 3 | 9 | 27 | 32 |
15+
| test.cpp:150:28:150:28 | , | 21 | 4 | 5 | 28 | 28 |
16+
| test.cpp:150:29:150:30 | \\w | 21 | 5 | 7 | 29 | 30 |
17+
| test.cpp:150:35:150:36 | \\) | 21 | 11 | 13 | 35 | 36 |
18+
| test.cpp:150:37:150:37 | $ | 21 | 13 | 14 | 37 | 37 |
19+
| test.cpp:153:25:153:25 | a | 21 | 0 | 1 | 25 | 25 |
20+
| test.cpp:153:25:153:26 | a+ | 21 | 0 | 2 | 25 | 26 |
21+
| test.cpp:153:25:153:27 | a+b | 21 | 0 | 3 | 25 | 27 |
22+
| test.cpp:153:27:153:27 | b | 21 | 2 | 3 | 27 | 27 |
23+
| test.cpp:156:24:156:24 | a | 22 | 0 | 1 | 24 | 24 |
24+
| test.cpp:156:24:156:25 | a+ | 22 | 0 | 2 | 24 | 25 |
25+
| test.cpp:156:24:156:26 | a+b | 22 | 0 | 3 | 24 | 26 |
26+
| test.cpp:156:26:156:26 | b | 22 | 2 | 3 | 26 | 26 |
27+
| test.cpp:159:30:159:30 | a | 26 | 0 | 1 | 30 | 30 |
28+
| test.cpp:159:30:159:31 | a+ | 26 | 0 | 2 | 30 | 31 |
29+
| test.cpp:159:30:159:32 | a+b | 26 | 0 | 3 | 30 | 32 |
30+
| test.cpp:159:32:159:32 | b | 26 | 2 | 3 | 32 | 32 |
31+
| test.cpp:163:22:163:23 | \\s | 21 | 0 | 2 | 22 | 23 |
32+
| test.cpp:163:22:163:24 | \\s+ | 21 | 0 | 3 | 22 | 24 |
33+
| test.cpp:166:22:166:22 | a | 21 | 0 | 1 | 22 | 22 |
34+
| test.cpp:166:22:166:25 | a\\.b | 21 | 0 | 4 | 22 | 25 |
35+
| test.cpp:166:23:166:24 | \\. | 21 | 1 | 3 | 23 | 24 |
36+
| test.cpp:166:25:166:25 | b | 21 | 3 | 4 | 25 | 25 |

0 commit comments

Comments
 (0)