Skip to content

Commit 8d45199

Browse files
Copilotjketema
authored andcommitted
C++: Implement \cX control escapes
1 parent 24251de commit 8d45199

3 files changed

Lines changed: 11 additions & 22 deletions

File tree

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,8 +322,11 @@ abstract class RegExp extends StringLiteral {
322322
// wide hex char \uhhhh
323323
this.getChar(start + 1) = "u" and end = start + 6
324324
or
325+
// control char \cX
326+
this.getChar(start + 1) = "c" and end = start + 3
327+
or
325328
// escape not handled above; update when adding a new case
326-
not this.getChar(start + 1) in ["x", "u"] and
329+
not this.getChar(start + 1) in ["x", "u", "c"] and
327330
not exists(this.getChar(start + 1).toInt()) and
328331
end = start + 2
329332
)

‎cpp/ql/test/library-tests/regex/parse.expected‎

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -401,21 +401,12 @@ regexp.cpp:
401401

402402
# 81| [RegExpConstant, RegExpEscape] \u{987
403403

404-
# 84| [RegExpConstant, RegExpEscape] \c
405-
406-
# 84| [RegExpSequence] \cA
407-
#-----| 0 -> [RegExpConstant, RegExpEscape] \c
408-
#-----| 1 -> [RegExpConstant, RegExpNormalChar] A
409-
410-
# 84| [RegExpConstant, RegExpNormalChar] A
404+
# 84| [RegExpConstant, RegExpEscape] \cA
411405

412406
# 85| [RegExpCharacterClass] [\cZ]
413-
#-----| 0 -> [RegExpConstant, RegExpEscape] \c
414-
#-----| 1 -> [RegExpConstant, RegExpNormalChar] Z
415-
416-
# 85| [RegExpConstant, RegExpEscape] \c
407+
#-----| 0 -> [RegExpConstant, RegExpEscape] \cZ
417408

418-
# 85| [RegExpConstant, RegExpNormalChar] Z
409+
# 85| [RegExpConstant, RegExpEscape] \cZ
419410

420411
# 88| [RegExpConstant, RegExpNormalChar] a
421412

‎cpp/ql/test/library-tests/regex/regexp.expected‎

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -150,12 +150,9 @@ term
150150
| regexp.cpp:75:37:75:37 | f | RegExpConstant,RegExpNormalChar |
151151
| regexp.cpp:78:22:78:30 | [:digit:] | RegExpNamedCharacterProperty |
152152
| regexp.cpp:81:19:81:24 | \\u{987 | RegExpConstant,RegExpEscape |
153-
| regexp.cpp:84:21:84:22 | \\c | RegExpConstant,RegExpEscape |
154-
| regexp.cpp:84:21:84:23 | \\cA | RegExpSequence |
155-
| regexp.cpp:84:23:84:23 | A | RegExpConstant,RegExpNormalChar |
153+
| regexp.cpp:84:21:84:23 | \\cA | RegExpConstant,RegExpEscape |
156154
| regexp.cpp:85:21:85:25 | [\\cZ] | RegExpCharacterClass |
157-
| regexp.cpp:85:22:85:23 | \\c | RegExpConstant,RegExpEscape |
158-
| regexp.cpp:85:24:85:24 | Z | RegExpConstant,RegExpNormalChar |
155+
| regexp.cpp:85:22:85:24 | \\cZ | RegExpConstant,RegExpEscape |
159156
| regexp.cpp:88:25:88:25 | a | RegExpConstant,RegExpNormalChar |
160157
| regexp.cpp:88:25:88:28 | a\\nb | RegExpSequence |
161158
| regexp.cpp:88:26:88:27 | \\n | RegExpConstant,RegExpEscape |
@@ -272,10 +269,8 @@ regExpNormalCharValue
272269
| regexp.cpp:75:35:75:35 | a | a |
273270
| regexp.cpp:75:37:75:37 | f | f |
274271
| regexp.cpp:81:19:81:24 | \\u{987 | \u0987 |
275-
| regexp.cpp:84:21:84:22 | \\c | c |
276-
| regexp.cpp:84:23:84:23 | A | A |
277-
| regexp.cpp:85:22:85:23 | \\c | c |
278-
| regexp.cpp:85:24:85:24 | Z | Z |
272+
| regexp.cpp:84:21:84:23 | \\cA | cA |
273+
| regexp.cpp:85:22:85:24 | \\cZ | cZ |
279274
| regexp.cpp:88:25:88:25 | a | a |
280275
| regexp.cpp:88:26:88:27 | \\n | \n |
281276
| regexp.cpp:88:28:88:28 | b | b |

0 commit comments

Comments
 (0)