From 8d53e365d60ff2de96922655df04fa9d5c4a8a42 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 21 Jul 2026 12:21:45 +0000 Subject: [PATCH] Commit 5: Port missing POSIX-bracket parse cases from PR #22200 Add corpus cases: bare [:alpha:], mid-pattern a[:b:]c, POSIX class as range endpoint [[:alpha:]-z], malformed [[:alpha], leading literal ] combined with a POSIX class []a[:alpha:]], three POSIX classes in one class, additional names [[:xdigit:]] / [[:blank:]] / [[:cntrl:]] / [[:graph:]], and the integration case combining all of the above. The regenerated parse.expected reveals genuine mis-parses that this commit deliberately records (fixes in Commit 6): - unnested [:alpha:] and [:b:] are treated as RegExpNamedCharacterProperty even though POSIX brackets are only valid inside a character class, - [[:alpha:]-z] emits a spurious [RegExpCharacterRange] ":]-z" instead of a POSIX class + literal '-' + 'z'. Bundle: github/codeql-action codeql-bundle-v2.26.1 (CodeQL CLI 2.26.1). --- .../library-tests/regex/locations.expected | 127 +++++++--- .../test/library-tests/regex/parse.expected | 232 ++++++++++++++---- .../test/library-tests/regex/regexp.expected | 194 ++++++++++----- cpp/ql/test/library-tests/regex/test.cpp | 27 ++ 4 files changed, 437 insertions(+), 143 deletions(-) diff --git a/cpp/ql/test/library-tests/regex/locations.expected b/cpp/ql/test/library-tests/regex/locations.expected index d465969f899..f9fba8ee68c 100644 --- a/cpp/ql/test/library-tests/regex/locations.expected +++ b/cpp/ql/test/library-tests/regex/locations.expected @@ -1,40 +1,87 @@ -| test.cpp:144:23:144:23 | a | 22 | 0 | 1 | 23 | 23 | -| test.cpp:144:23:144:24 | a+ | 22 | 0 | 2 | 23 | 24 | -| test.cpp:144:23:144:25 | a+b | 22 | 0 | 3 | 23 | 25 | -| test.cpp:144:25:144:25 | b | 22 | 2 | 3 | 25 | 25 | -| test.cpp:147:23:147:23 | a | 20 | 0 | 1 | 23 | 23 | -| test.cpp:147:23:147:24 | a+ | 20 | 0 | 2 | 23 | 24 | -| test.cpp:147:23:147:25 | a+b | 20 | 0 | 3 | 23 | 25 | -| test.cpp:147:25:147:25 | b | 20 | 2 | 3 | 25 | 25 | -| test.cpp:150:24:150:25 | \\s | 21 | 0 | 2 | 24 | 25 | -| test.cpp:150:24:150:26 | \\s+ | 21 | 0 | 3 | 24 | 26 | -| test.cpp:150:24:150:27 | \\s+$ | 21 | 0 | 4 | 24 | 27 | -| test.cpp:150:27:150:27 | $ | 21 | 3 | 4 | 27 | 27 | -| test.cpp:153:24:153:25 | \\( | 21 | 0 | 2 | 24 | 25 | -| test.cpp:153:24:153:37 | \\(([,\\w]+)+\\)$ | 21 | 0 | 14 | 24 | 37 | -| test.cpp:153:26:153:33 | ([,\\w]+) | 21 | 2 | 10 | 26 | 33 | -| test.cpp:153:26:153:34 | ([,\\w]+)+ | 21 | 2 | 11 | 26 | 34 | -| test.cpp:153:27:153:31 | [,\\w] | 21 | 3 | 8 | 27 | 31 | -| test.cpp:153:27:153:32 | [,\\w]+ | 21 | 3 | 9 | 27 | 32 | -| test.cpp:153:28:153:28 | , | 21 | 4 | 5 | 28 | 28 | -| test.cpp:153:29:153:30 | \\w | 21 | 5 | 7 | 29 | 30 | -| test.cpp:153:35:153:36 | \\) | 21 | 11 | 13 | 35 | 36 | -| test.cpp:153:37:153:37 | $ | 21 | 13 | 14 | 37 | 37 | -| test.cpp:156:25:156:25 | a | 21 | 0 | 1 | 25 | 25 | -| test.cpp:156:25:156:26 | a+ | 21 | 0 | 2 | 25 | 26 | -| test.cpp:156:25:156:27 | a+b | 21 | 0 | 3 | 25 | 27 | -| test.cpp:156:27:156:27 | b | 21 | 2 | 3 | 27 | 27 | -| test.cpp:159:24:159:24 | a | 22 | 0 | 1 | 24 | 24 | -| test.cpp:159:24:159:25 | a+ | 22 | 0 | 2 | 24 | 25 | -| test.cpp:159:24:159:26 | a+b | 22 | 0 | 3 | 24 | 26 | -| test.cpp:159:26:159:26 | b | 22 | 2 | 3 | 26 | 26 | -| test.cpp:162:30:162:30 | a | 26 | 0 | 1 | 30 | 30 | -| test.cpp:162:30:162:31 | a+ | 26 | 0 | 2 | 30 | 31 | -| test.cpp:162:30:162:32 | a+b | 26 | 0 | 3 | 30 | 32 | -| test.cpp:162:32:162:32 | b | 26 | 2 | 3 | 32 | 32 | -| test.cpp:166:22:166:23 | \\s | 21 | 0 | 2 | 22 | 23 | -| test.cpp:166:22:166:24 | \\s+ | 21 | 0 | 3 | 22 | 24 | -| test.cpp:169:22:169:22 | a | 21 | 0 | 1 | 22 | 22 | -| test.cpp:169:22:169:25 | a\\.b | 21 | 0 | 4 | 22 | 25 | -| test.cpp:169:23:169:24 | \\. | 21 | 1 | 3 | 23 | 24 | -| test.cpp:169:25:169:25 | b | 21 | 3 | 4 | 25 | 25 | +| test.cpp:143:24:143:32 | [[:alpha] | 23 | 0 | 9 | 24 | 32 | +| test.cpp:143:25:143:25 | [ | 23 | 1 | 2 | 25 | 25 | +| test.cpp:143:26:143:26 | : | 23 | 2 | 3 | 26 | 26 | +| test.cpp:143:27:143:27 | a | 23 | 3 | 4 | 27 | 27 | +| test.cpp:143:28:143:28 | l | 23 | 4 | 5 | 28 | 28 | +| test.cpp:143:29:143:29 | p | 23 | 5 | 6 | 29 | 29 | +| test.cpp:143:30:143:30 | h | 23 | 6 | 7 | 30 | 30 | +| test.cpp:143:31:143:31 | a | 23 | 7 | 8 | 31 | 31 | +| test.cpp:146:24:146:36 | []a[:alpha:]] | 23 | 0 | 13 | 24 | 36 | +| test.cpp:146:25:146:25 | ] | 23 | 1 | 2 | 25 | 25 | +| test.cpp:146:26:146:26 | a | 23 | 2 | 3 | 26 | 26 | +| test.cpp:146:27:146:35 | [:alpha:] | 23 | 3 | 12 | 27 | 35 | +| test.cpp:149:25:149:53 | [[:alpha:][:digit:][:space:]] | 24 | 0 | 29 | 25 | 53 | +| test.cpp:149:26:149:34 | [:alpha:] | 24 | 1 | 10 | 26 | 34 | +| test.cpp:149:35:149:43 | [:digit:] | 24 | 10 | 19 | 35 | 43 | +| test.cpp:149:44:149:52 | [:space:] | 24 | 19 | 28 | 44 | 52 | +| test.cpp:152:25:152:36 | [[:xdigit:]] | 24 | 0 | 12 | 25 | 36 | +| test.cpp:152:26:152:35 | [:xdigit:] | 24 | 1 | 11 | 26 | 35 | +| test.cpp:153:25:153:35 | [[:blank:]] | 24 | 0 | 11 | 25 | 35 | +| test.cpp:153:26:153:34 | [:blank:] | 24 | 1 | 10 | 26 | 34 | +| test.cpp:154:25:154:35 | [[:cntrl:]] | 24 | 0 | 11 | 25 | 35 | +| test.cpp:154:26:154:34 | [:cntrl:] | 24 | 1 | 10 | 26 | 34 | +| test.cpp:155:25:155:35 | [[:graph:]] | 24 | 0 | 11 | 25 | 35 | +| test.cpp:155:26:155:34 | [:graph:] | 24 | 1 | 10 | 26 | 34 | +| test.cpp:158:25:158:25 | ^ | 24 | 0 | 1 | 25 | 25 | +| test.cpp:158:25:158:92 | ^([[:alpha:]]+[[:digit:]]*[[:space:]]?)+([[:punct:]]\|[[:xdigit:]])+$ | 24 | 0 | 68 | 25 | 92 | +| test.cpp:158:26:158:63 | ([[:alpha:]]+[[:digit:]]*[[:space:]]?) | 24 | 1 | 39 | 26 | 63 | +| test.cpp:158:26:158:64 | ([[:alpha:]]+[[:digit:]]*[[:space:]]?)+ | 24 | 1 | 40 | 26 | 64 | +| test.cpp:158:27:158:37 | [[:alpha:]] | 24 | 2 | 13 | 27 | 37 | +| test.cpp:158:27:158:38 | [[:alpha:]]+ | 24 | 2 | 14 | 27 | 38 | +| test.cpp:158:27:158:62 | [[:alpha:]]+[[:digit:]]*[[:space:]]? | 24 | 2 | 38 | 27 | 62 | +| test.cpp:158:28:158:36 | [:alpha:] | 24 | 3 | 12 | 28 | 36 | +| test.cpp:158:39:158:49 | [[:digit:]] | 24 | 14 | 25 | 39 | 49 | +| test.cpp:158:39:158:50 | [[:digit:]]* | 24 | 14 | 26 | 39 | 50 | +| test.cpp:158:40:158:48 | [:digit:] | 24 | 15 | 24 | 40 | 48 | +| test.cpp:158:51:158:61 | [[:space:]] | 24 | 26 | 37 | 51 | 61 | +| test.cpp:158:51:158:62 | [[:space:]]? | 24 | 26 | 38 | 51 | 62 | +| test.cpp:158:52:158:60 | [:space:] | 24 | 27 | 36 | 52 | 60 | +| test.cpp:158:65:158:90 | ([[:punct:]]\|[[:xdigit:]]) | 24 | 40 | 66 | 65 | 90 | +| test.cpp:158:65:158:91 | ([[:punct:]]\|[[:xdigit:]])+ | 24 | 40 | 67 | 65 | 91 | +| test.cpp:158:66:158:76 | [[:punct:]] | 24 | 41 | 52 | 66 | 76 | +| test.cpp:158:66:158:89 | [[:punct:]]\|[[:xdigit:]] | 24 | 41 | 65 | 66 | 89 | +| test.cpp:158:67:158:75 | [:punct:] | 24 | 42 | 51 | 67 | 75 | +| test.cpp:158:78:158:89 | [[:xdigit:]] | 24 | 53 | 65 | 78 | 89 | +| test.cpp:158:79:158:88 | [:xdigit:] | 24 | 54 | 64 | 79 | 88 | +| test.cpp:158:92:158:92 | $ | 24 | 67 | 68 | 92 | 92 | +| test.cpp:163:21:163:26 | \\u9879 | 20 | 0 | 6 | 21 | 26 | +| test.cpp:171:23:171:23 | a | 22 | 0 | 1 | 23 | 23 | +| test.cpp:171:23:171:24 | a+ | 22 | 0 | 2 | 23 | 24 | +| test.cpp:171:23:171:25 | a+b | 22 | 0 | 3 | 23 | 25 | +| test.cpp:171:25:171:25 | b | 22 | 2 | 3 | 25 | 25 | +| test.cpp:174:23:174:23 | a | 20 | 0 | 1 | 23 | 23 | +| test.cpp:174:23:174:24 | a+ | 20 | 0 | 2 | 23 | 24 | +| test.cpp:174:23:174:25 | a+b | 20 | 0 | 3 | 23 | 25 | +| test.cpp:174:25:174:25 | b | 20 | 2 | 3 | 25 | 25 | +| test.cpp:177:24:177:25 | \\s | 21 | 0 | 2 | 24 | 25 | +| test.cpp:177:24:177:26 | \\s+ | 21 | 0 | 3 | 24 | 26 | +| test.cpp:177:24:177:27 | \\s+$ | 21 | 0 | 4 | 24 | 27 | +| test.cpp:177:27:177:27 | $ | 21 | 3 | 4 | 27 | 27 | +| test.cpp:180:24:180:25 | \\( | 21 | 0 | 2 | 24 | 25 | +| test.cpp:180:24:180:37 | \\(([,\\w]+)+\\)$ | 21 | 0 | 14 | 24 | 37 | +| test.cpp:180:26:180:33 | ([,\\w]+) | 21 | 2 | 10 | 26 | 33 | +| test.cpp:180:26:180:34 | ([,\\w]+)+ | 21 | 2 | 11 | 26 | 34 | +| test.cpp:180:27:180:31 | [,\\w] | 21 | 3 | 8 | 27 | 31 | +| test.cpp:180:27:180:32 | [,\\w]+ | 21 | 3 | 9 | 27 | 32 | +| test.cpp:180:28:180:28 | , | 21 | 4 | 5 | 28 | 28 | +| test.cpp:180:29:180:30 | \\w | 21 | 5 | 7 | 29 | 30 | +| test.cpp:180:35:180:36 | \\) | 21 | 11 | 13 | 35 | 36 | +| test.cpp:180:37:180:37 | $ | 21 | 13 | 14 | 37 | 37 | +| test.cpp:183:25:183:25 | a | 21 | 0 | 1 | 25 | 25 | +| test.cpp:183:25:183:26 | a+ | 21 | 0 | 2 | 25 | 26 | +| test.cpp:183:25:183:27 | a+b | 21 | 0 | 3 | 25 | 27 | +| test.cpp:183:27:183:27 | b | 21 | 2 | 3 | 27 | 27 | +| test.cpp:186:24:186:24 | a | 22 | 0 | 1 | 24 | 24 | +| test.cpp:186:24:186:25 | a+ | 22 | 0 | 2 | 24 | 25 | +| test.cpp:186:24:186:26 | a+b | 22 | 0 | 3 | 24 | 26 | +| test.cpp:186:26:186:26 | b | 22 | 2 | 3 | 26 | 26 | +| test.cpp:189:30:189:30 | a | 26 | 0 | 1 | 30 | 30 | +| test.cpp:189:30:189:31 | a+ | 26 | 0 | 2 | 30 | 31 | +| test.cpp:189:30:189:32 | a+b | 26 | 0 | 3 | 30 | 32 | +| test.cpp:189:32:189:32 | b | 26 | 2 | 3 | 32 | 32 | +| test.cpp:193:22:193:23 | \\s | 21 | 0 | 2 | 22 | 23 | +| test.cpp:193:22:193:24 | \\s+ | 21 | 0 | 3 | 22 | 24 | +| test.cpp:196:22:196:22 | a | 21 | 0 | 1 | 22 | 22 | +| test.cpp:196:22:196:25 | a\\.b | 21 | 0 | 4 | 22 | 25 | +| test.cpp:196:23:196:24 | \\. | 21 | 1 | 3 | 23 | 24 | +| test.cpp:196:25:196:25 | b | 21 | 3 | 4 | 25 | 25 | diff --git a/cpp/ql/test/library-tests/regex/parse.expected b/cpp/ql/test/library-tests/regex/parse.expected index e088f913686..47307602ac8 100644 --- a/cpp/ql/test/library-tests/regex/parse.expected +++ b/cpp/ql/test/library-tests/regex/parse.expected @@ -517,115 +517,265 @@ test.cpp: # 131| [RegExpNamedCharacterProperty] [:digit:] -# 136| [RegExpConstant, RegExpEscape] \u9879 +# 134| [RegExpNamedCharacterProperty] [:alpha:] -# 144| [RegExpConstant, RegExpNormalChar] a +# 137| [RegExpConstant, RegExpNormalChar] a -# 144| [RegExpPlus] a+ +# 137| [RegExpNamedCharacterProperty] [:b:] + +# 137| [RegExpConstant, RegExpNormalChar] c + +# 140| [RegExpCharacterClass] [[:alpha:]-z] +#-----| 0 -> [RegExpNamedCharacterProperty] [:alpha:] + +# 140| [RegExpNamedCharacterProperty] [:alpha:] + +# 140| [RegExpCharacterRange] :]-z +#-----| 1 -> [RegExpConstant, RegExpNormalChar] z + +# 140| [RegExpConstant, RegExpNormalChar] - + +# 140| [RegExpConstant, RegExpNormalChar] z + +# 143| [RegExpCharacterClass] [[:alpha] +#-----| 0 -> [RegExpConstant, RegExpNormalChar] [ +#-----| 1 -> [RegExpConstant, RegExpNormalChar] : +#-----| 2 -> [RegExpConstant, RegExpNormalChar] a +#-----| 3 -> [RegExpConstant, RegExpNormalChar] l +#-----| 4 -> [RegExpConstant, RegExpNormalChar] p +#-----| 5 -> [RegExpConstant, RegExpNormalChar] h +#-----| 6 -> [RegExpConstant, RegExpNormalChar] a + +# 143| [RegExpConstant, RegExpNormalChar] [ + +# 143| [RegExpConstant, RegExpNormalChar] : + +# 143| [RegExpConstant, RegExpNormalChar] a + +# 143| [RegExpConstant, RegExpNormalChar] l + +# 143| [RegExpConstant, RegExpNormalChar] p + +# 143| [RegExpConstant, RegExpNormalChar] h + +# 143| [RegExpConstant, RegExpNormalChar] a + +# 146| [RegExpCharacterClass] []a[:alpha:]] +#-----| 0 -> [RegExpConstant, RegExpNormalChar] ] +#-----| 1 -> [RegExpConstant, RegExpNormalChar] a +#-----| 2 -> [RegExpNamedCharacterProperty] [:alpha:] + +# 146| [RegExpConstant, RegExpNormalChar] ] + +# 146| [RegExpConstant, RegExpNormalChar] a + +# 146| [RegExpNamedCharacterProperty] [:alpha:] + +# 149| [RegExpCharacterClass] [[:alpha:][:digit:][:space:]] +#-----| 0 -> [RegExpNamedCharacterProperty] [:alpha:] +#-----| 1 -> [RegExpNamedCharacterProperty] [:digit:] +#-----| 2 -> [RegExpNamedCharacterProperty] [:space:] + +# 149| [RegExpNamedCharacterProperty] [:alpha:] + +# 149| [RegExpNamedCharacterProperty] [:digit:] + +# 149| [RegExpNamedCharacterProperty] [:space:] + +# 152| [RegExpCharacterClass] [[:xdigit:]] +#-----| 0 -> [RegExpNamedCharacterProperty] [:xdigit:] + +# 152| [RegExpNamedCharacterProperty] [:xdigit:] + +# 153| [RegExpCharacterClass] [[:blank:]] +#-----| 0 -> [RegExpNamedCharacterProperty] [:blank:] + +# 153| [RegExpNamedCharacterProperty] [:blank:] + +# 154| [RegExpCharacterClass] [[:cntrl:]] +#-----| 0 -> [RegExpNamedCharacterProperty] [:cntrl:] + +# 154| [RegExpNamedCharacterProperty] [:cntrl:] + +# 155| [RegExpCharacterClass] [[:graph:]] +#-----| 0 -> [RegExpNamedCharacterProperty] [:graph:] + +# 155| [RegExpNamedCharacterProperty] [:graph:] + +# 158| [RegExpCaret] ^ + +# 158| [RegExpSequence] ^([[:alpha:]]+[[:digit:]]*[[:space:]]?)+([[:punct:]]|[[:xdigit:]])+$ +#-----| 0 -> [RegExpCaret] ^ +#-----| 1 -> [RegExpPlus] ([[:alpha:]]+[[:digit:]]*[[:space:]]?)+ +#-----| 2 -> [RegExpPlus] ([[:punct:]]|[[:xdigit:]])+ +#-----| 3 -> [RegExpDollar] $ + +# 158| [RegExpGroup] ([[:alpha:]]+[[:digit:]]*[[:space:]]?) +#-----| 0 -> [RegExpSequence] [[:alpha:]]+[[:digit:]]*[[:space:]]? + +# 158| [RegExpPlus] ([[:alpha:]]+[[:digit:]]*[[:space:]]?)+ +#-----| 0 -> [RegExpGroup] ([[:alpha:]]+[[:digit:]]*[[:space:]]?) + +# 158| [RegExpCharacterClass] [[:alpha:]] +#-----| 0 -> [RegExpNamedCharacterProperty] [:alpha:] + +# 158| [RegExpPlus] [[:alpha:]]+ +#-----| 0 -> [RegExpCharacterClass] [[:alpha:]] + +# 158| [RegExpSequence] [[:alpha:]]+[[:digit:]]*[[:space:]]? +#-----| 0 -> [RegExpPlus] [[:alpha:]]+ +#-----| 1 -> [RegExpStar] [[:digit:]]* +#-----| 2 -> [RegExpOpt] [[:space:]]? + +# 158| [RegExpNamedCharacterProperty] [:alpha:] + +# 158| [RegExpCharacterClass] [[:digit:]] +#-----| 0 -> [RegExpNamedCharacterProperty] [:digit:] + +# 158| [RegExpStar] [[:digit:]]* +#-----| 0 -> [RegExpCharacterClass] [[:digit:]] + +# 158| [RegExpNamedCharacterProperty] [:digit:] + +# 158| [RegExpCharacterClass] [[:space:]] +#-----| 0 -> [RegExpNamedCharacterProperty] [:space:] + +# 158| [RegExpOpt] [[:space:]]? +#-----| 0 -> [RegExpCharacterClass] [[:space:]] + +# 158| [RegExpNamedCharacterProperty] [:space:] + +# 158| [RegExpGroup] ([[:punct:]]|[[:xdigit:]]) +#-----| 0 -> [RegExpAlt] [[:punct:]]|[[:xdigit:]] + +# 158| [RegExpPlus] ([[:punct:]]|[[:xdigit:]])+ +#-----| 0 -> [RegExpGroup] ([[:punct:]]|[[:xdigit:]]) + +# 158| [RegExpCharacterClass] [[:punct:]] +#-----| 0 -> [RegExpNamedCharacterProperty] [:punct:] + +# 158| [RegExpAlt] [[:punct:]]|[[:xdigit:]] +#-----| 0 -> [RegExpCharacterClass] [[:punct:]] +#-----| 1 -> [RegExpCharacterClass] [[:xdigit:]] + +# 158| [RegExpNamedCharacterProperty] [:punct:] + +# 158| [RegExpCharacterClass] [[:xdigit:]] +#-----| 0 -> [RegExpNamedCharacterProperty] [:xdigit:] + +# 158| [RegExpNamedCharacterProperty] [:xdigit:] + +# 158| [RegExpDollar] $ + +# 163| [RegExpConstant, RegExpEscape] \u9879 + +# 171| [RegExpConstant, RegExpNormalChar] a + +# 171| [RegExpPlus] a+ #-----| 0 -> [RegExpConstant, RegExpNormalChar] a -# 144| [RegExpSequence] a+b +# 171| [RegExpSequence] a+b #-----| 0 -> [RegExpPlus] a+ #-----| 1 -> [RegExpConstant, RegExpNormalChar] b -# 144| [RegExpConstant, RegExpNormalChar] b +# 171| [RegExpConstant, RegExpNormalChar] b -# 147| [RegExpConstant, RegExpNormalChar] a +# 174| [RegExpConstant, RegExpNormalChar] a -# 147| [RegExpPlus] a+ +# 174| [RegExpPlus] a+ #-----| 0 -> [RegExpConstant, RegExpNormalChar] a -# 147| [RegExpSequence] a+b +# 174| [RegExpSequence] a+b #-----| 0 -> [RegExpPlus] a+ #-----| 1 -> [RegExpConstant, RegExpNormalChar] b -# 147| [RegExpConstant, RegExpNormalChar] b +# 174| [RegExpConstant, RegExpNormalChar] b -# 150| [RegExpCharacterClassEscape] \s +# 177| [RegExpCharacterClassEscape] \s -# 150| [RegExpPlus] \s+ +# 177| [RegExpPlus] \s+ #-----| 0 -> [RegExpCharacterClassEscape] \s -# 150| [RegExpSequence] \s+$ +# 177| [RegExpSequence] \s+$ #-----| 0 -> [RegExpPlus] \s+ #-----| 1 -> [RegExpDollar] $ -# 150| [RegExpDollar] $ +# 177| [RegExpDollar] $ -# 153| [RegExpConstant, RegExpEscape] \( +# 180| [RegExpConstant, RegExpEscape] \( -# 153| [RegExpSequence] \(([,\w]+)+\)$ +# 180| [RegExpSequence] \(([,\w]+)+\)$ #-----| 0 -> [RegExpConstant, RegExpEscape] \( #-----| 1 -> [RegExpPlus] ([,\w]+)+ #-----| 2 -> [RegExpConstant, RegExpEscape] \) #-----| 3 -> [RegExpDollar] $ -# 153| [RegExpGroup] ([,\w]+) +# 180| [RegExpGroup] ([,\w]+) #-----| 0 -> [RegExpPlus] [,\w]+ -# 153| [RegExpPlus] ([,\w]+)+ +# 180| [RegExpPlus] ([,\w]+)+ #-----| 0 -> [RegExpGroup] ([,\w]+) -# 153| [RegExpCharacterClass] [,\w] +# 180| [RegExpCharacterClass] [,\w] #-----| 0 -> [RegExpConstant, RegExpNormalChar] , #-----| 1 -> [RegExpCharacterClassEscape] \w -# 153| [RegExpPlus] [,\w]+ +# 180| [RegExpPlus] [,\w]+ #-----| 0 -> [RegExpCharacterClass] [,\w] -# 153| [RegExpConstant, RegExpNormalChar] , +# 180| [RegExpConstant, RegExpNormalChar] , -# 153| [RegExpCharacterClassEscape] \w +# 180| [RegExpCharacterClassEscape] \w -# 153| [RegExpConstant, RegExpEscape] \) +# 180| [RegExpConstant, RegExpEscape] \) -# 153| [RegExpDollar] $ +# 180| [RegExpDollar] $ -# 156| [RegExpConstant, RegExpNormalChar] a +# 183| [RegExpConstant, RegExpNormalChar] a -# 156| [RegExpPlus] a+ +# 183| [RegExpPlus] a+ #-----| 0 -> [RegExpConstant, RegExpNormalChar] a -# 156| [RegExpSequence] a+b +# 183| [RegExpSequence] a+b #-----| 0 -> [RegExpPlus] a+ #-----| 1 -> [RegExpConstant, RegExpNormalChar] b -# 156| [RegExpConstant, RegExpNormalChar] b +# 183| [RegExpConstant, RegExpNormalChar] b -# 159| [RegExpConstant, RegExpNormalChar] a +# 186| [RegExpConstant, RegExpNormalChar] a -# 159| [RegExpPlus] a+ +# 186| [RegExpPlus] a+ #-----| 0 -> [RegExpConstant, RegExpNormalChar] a -# 159| [RegExpSequence] a+b +# 186| [RegExpSequence] a+b #-----| 0 -> [RegExpPlus] a+ #-----| 1 -> [RegExpConstant, RegExpNormalChar] b -# 159| [RegExpConstant, RegExpNormalChar] b +# 186| [RegExpConstant, RegExpNormalChar] b -# 162| [RegExpConstant, RegExpNormalChar] a +# 189| [RegExpConstant, RegExpNormalChar] a -# 162| [RegExpPlus] a+ +# 189| [RegExpPlus] a+ #-----| 0 -> [RegExpConstant, RegExpNormalChar] a -# 162| [RegExpSequence] a+b +# 189| [RegExpSequence] a+b #-----| 0 -> [RegExpPlus] a+ #-----| 1 -> [RegExpConstant, RegExpNormalChar] b -# 162| [RegExpConstant, RegExpNormalChar] b +# 189| [RegExpConstant, RegExpNormalChar] b -# 166| [RegExpCharacterClassEscape] \s +# 193| [RegExpCharacterClassEscape] \s -# 166| [RegExpPlus] \s+ +# 193| [RegExpPlus] \s+ #-----| 0 -> [RegExpCharacterClassEscape] \s -# 169| [RegExpConstant, RegExpNormalChar] a +# 196| [RegExpConstant, RegExpNormalChar] a -# 169| [RegExpSequence] a\.b +# 196| [RegExpSequence] a\.b #-----| 0 -> [RegExpConstant, RegExpNormalChar] a #-----| 1 -> [RegExpConstant, RegExpEscape] \. #-----| 2 -> [RegExpConstant, RegExpNormalChar] b -# 169| [RegExpConstant, RegExpEscape] \. +# 196| [RegExpConstant, RegExpEscape] \. -# 169| [RegExpConstant, RegExpNormalChar] b +# 196| [RegExpConstant, RegExpNormalChar] b diff --git a/cpp/ql/test/library-tests/regex/regexp.expected b/cpp/ql/test/library-tests/regex/regexp.expected index edb1f4ddfa0..e9a8bc0511d 100644 --- a/cpp/ql/test/library-tests/regex/regexp.expected +++ b/cpp/ql/test/library-tests/regex/regexp.expected @@ -8,7 +8,9 @@ groupNumber | test.cpp:111:21:111:30 | (?\\w+) | 1 | | test.cpp:115:23:115:26 | (a+) | 1 | | test.cpp:116:23:116:32 | (?q+) | 1 | -| test.cpp:153:26:153:33 | ([,\\w]+) | 1 | +| test.cpp:158:26:158:63 | ([[:alpha:]]+[[:digit:]]*[[:space:]]?) | 1 | +| test.cpp:158:65:158:90 | ([[:punct:]]\|[[:xdigit:]]) | 2 | +| test.cpp:180:26:180:33 | ([,\\w]+) | 1 | term | test.cpp:33:21:33:23 | abc | RegExpConstant,RegExpNormalChar | | test.cpp:36:22:36:22 | a | RegExpConstant,RegExpNormalChar | @@ -199,47 +201,102 @@ term | test.cpp:128:37:128:39 | a-f | RegExpCharacterRange | | test.cpp:128:39:128:39 | f | RegExpConstant,RegExpNormalChar | | test.cpp:131:24:131:32 | [:digit:] | RegExpNamedCharacterProperty | -| test.cpp:136:21:136:26 | \\u9879 | RegExpConstant,RegExpEscape | -| test.cpp:144:23:144:23 | a | RegExpConstant,RegExpNormalChar | -| test.cpp:144:23:144:24 | a+ | RegExpPlus | -| test.cpp:144:23:144:25 | a+b | RegExpSequence | -| test.cpp:144:25:144:25 | b | RegExpConstant,RegExpNormalChar | -| test.cpp:147:23:147:23 | a | RegExpConstant,RegExpNormalChar | -| test.cpp:147:23:147:24 | a+ | RegExpPlus | -| test.cpp:147:23:147:25 | a+b | RegExpSequence | -| test.cpp:147:25:147:25 | b | RegExpConstant,RegExpNormalChar | -| test.cpp:150:24:150:25 | \\s | RegExpCharacterClassEscape | -| test.cpp:150:24:150:26 | \\s+ | RegExpPlus | -| test.cpp:150:24:150:27 | \\s+$ | RegExpSequence | -| test.cpp:150:27:150:27 | $ | RegExpDollar | -| test.cpp:153:24:153:25 | \\( | RegExpConstant,RegExpEscape | -| test.cpp:153:24:153:37 | \\(([,\\w]+)+\\)$ | RegExpSequence | -| test.cpp:153:26:153:33 | ([,\\w]+) | RegExpGroup | -| test.cpp:153:26:153:34 | ([,\\w]+)+ | RegExpPlus | -| test.cpp:153:27:153:31 | [,\\w] | RegExpCharacterClass | -| test.cpp:153:27:153:32 | [,\\w]+ | RegExpPlus | -| test.cpp:153:28:153:28 | , | RegExpConstant,RegExpNormalChar | -| test.cpp:153:29:153:30 | \\w | RegExpCharacterClassEscape | -| test.cpp:153:35:153:36 | \\) | RegExpConstant,RegExpEscape | -| test.cpp:153:37:153:37 | $ | RegExpDollar | -| test.cpp:156:25:156:25 | a | RegExpConstant,RegExpNormalChar | -| test.cpp:156:25:156:26 | a+ | RegExpPlus | -| test.cpp:156:25:156:27 | a+b | RegExpSequence | -| test.cpp:156:27:156:27 | b | RegExpConstant,RegExpNormalChar | -| test.cpp:159:24:159:24 | a | RegExpConstant,RegExpNormalChar | -| test.cpp:159:24:159:25 | a+ | RegExpPlus | -| test.cpp:159:24:159:26 | a+b | RegExpSequence | -| test.cpp:159:26:159:26 | b | RegExpConstant,RegExpNormalChar | -| test.cpp:162:30:162:30 | a | RegExpConstant,RegExpNormalChar | -| test.cpp:162:30:162:31 | a+ | RegExpPlus | -| test.cpp:162:30:162:32 | a+b | RegExpSequence | -| test.cpp:162:32:162:32 | b | RegExpConstant,RegExpNormalChar | -| test.cpp:166:22:166:23 | \\s | RegExpCharacterClassEscape | -| test.cpp:166:22:166:24 | \\s+ | RegExpPlus | -| test.cpp:169:22:169:22 | a | RegExpConstant,RegExpNormalChar | -| test.cpp:169:22:169:25 | a\\.b | RegExpSequence | -| test.cpp:169:23:169:24 | \\. | RegExpConstant,RegExpEscape | -| test.cpp:169:25:169:25 | b | RegExpConstant,RegExpNormalChar | +| test.cpp:134:24:134:32 | [:alpha:] | RegExpNamedCharacterProperty | +| test.cpp:137:24:137:24 | a | RegExpConstant,RegExpNormalChar | +| test.cpp:137:25:137:29 | [:b:] | RegExpNamedCharacterProperty | +| test.cpp:137:30:137:30 | c | RegExpConstant,RegExpNormalChar | +| test.cpp:140:24:140:36 | [[:alpha:]-z] | RegExpCharacterClass | +| test.cpp:140:25:140:33 | [:alpha:] | RegExpNamedCharacterProperty | +| test.cpp:140:32:140:35 | :]-z | RegExpCharacterRange | +| test.cpp:140:34:140:34 | - | RegExpConstant,RegExpNormalChar | +| test.cpp:140:35:140:35 | z | RegExpConstant,RegExpNormalChar | +| test.cpp:143:24:143:32 | [[:alpha] | RegExpCharacterClass | +| test.cpp:143:25:143:25 | [ | RegExpConstant,RegExpNormalChar | +| test.cpp:143:26:143:26 | : | RegExpConstant,RegExpNormalChar | +| test.cpp:143:27:143:27 | a | RegExpConstant,RegExpNormalChar | +| test.cpp:143:28:143:28 | l | RegExpConstant,RegExpNormalChar | +| test.cpp:143:29:143:29 | p | RegExpConstant,RegExpNormalChar | +| test.cpp:143:30:143:30 | h | RegExpConstant,RegExpNormalChar | +| test.cpp:143:31:143:31 | a | RegExpConstant,RegExpNormalChar | +| test.cpp:146:24:146:36 | []a[:alpha:]] | RegExpCharacterClass | +| test.cpp:146:25:146:25 | ] | RegExpConstant,RegExpNormalChar | +| test.cpp:146:26:146:26 | a | RegExpConstant,RegExpNormalChar | +| test.cpp:146:27:146:35 | [:alpha:] | RegExpNamedCharacterProperty | +| test.cpp:149:25:149:53 | [[:alpha:][:digit:][:space:]] | RegExpCharacterClass | +| test.cpp:149:26:149:34 | [:alpha:] | RegExpNamedCharacterProperty | +| test.cpp:149:35:149:43 | [:digit:] | RegExpNamedCharacterProperty | +| test.cpp:149:44:149:52 | [:space:] | RegExpNamedCharacterProperty | +| test.cpp:152:25:152:36 | [[:xdigit:]] | RegExpCharacterClass | +| test.cpp:152:26:152:35 | [:xdigit:] | RegExpNamedCharacterProperty | +| test.cpp:153:25:153:35 | [[:blank:]] | RegExpCharacterClass | +| test.cpp:153:26:153:34 | [:blank:] | RegExpNamedCharacterProperty | +| test.cpp:154:25:154:35 | [[:cntrl:]] | RegExpCharacterClass | +| test.cpp:154:26:154:34 | [:cntrl:] | RegExpNamedCharacterProperty | +| test.cpp:155:25:155:35 | [[:graph:]] | RegExpCharacterClass | +| test.cpp:155:26:155:34 | [:graph:] | RegExpNamedCharacterProperty | +| test.cpp:158:25:158:25 | ^ | RegExpCaret | +| test.cpp:158:25:158:92 | ^([[:alpha:]]+[[:digit:]]*[[:space:]]?)+([[:punct:]]\|[[:xdigit:]])+$ | RegExpSequence | +| test.cpp:158:26:158:63 | ([[:alpha:]]+[[:digit:]]*[[:space:]]?) | RegExpGroup | +| test.cpp:158:26:158:64 | ([[:alpha:]]+[[:digit:]]*[[:space:]]?)+ | RegExpPlus | +| test.cpp:158:27:158:37 | [[:alpha:]] | RegExpCharacterClass | +| test.cpp:158:27:158:38 | [[:alpha:]]+ | RegExpPlus | +| test.cpp:158:27:158:62 | [[:alpha:]]+[[:digit:]]*[[:space:]]? | RegExpSequence | +| test.cpp:158:28:158:36 | [:alpha:] | RegExpNamedCharacterProperty | +| test.cpp:158:39:158:49 | [[:digit:]] | RegExpCharacterClass | +| test.cpp:158:39:158:50 | [[:digit:]]* | RegExpStar | +| test.cpp:158:40:158:48 | [:digit:] | RegExpNamedCharacterProperty | +| test.cpp:158:51:158:61 | [[:space:]] | RegExpCharacterClass | +| test.cpp:158:51:158:62 | [[:space:]]? | RegExpOpt | +| test.cpp:158:52:158:60 | [:space:] | RegExpNamedCharacterProperty | +| test.cpp:158:65:158:90 | ([[:punct:]]\|[[:xdigit:]]) | RegExpGroup | +| test.cpp:158:65:158:91 | ([[:punct:]]\|[[:xdigit:]])+ | RegExpPlus | +| test.cpp:158:66:158:76 | [[:punct:]] | RegExpCharacterClass | +| test.cpp:158:66:158:89 | [[:punct:]]\|[[:xdigit:]] | RegExpAlt | +| test.cpp:158:67:158:75 | [:punct:] | RegExpNamedCharacterProperty | +| test.cpp:158:78:158:89 | [[:xdigit:]] | RegExpCharacterClass | +| test.cpp:158:79:158:88 | [:xdigit:] | RegExpNamedCharacterProperty | +| test.cpp:158:92:158:92 | $ | RegExpDollar | +| test.cpp:163:21:163:26 | \\u9879 | RegExpConstant,RegExpEscape | +| test.cpp:171:23:171:23 | a | RegExpConstant,RegExpNormalChar | +| test.cpp:171:23:171:24 | a+ | RegExpPlus | +| test.cpp:171:23:171:25 | a+b | RegExpSequence | +| test.cpp:171:25:171:25 | b | RegExpConstant,RegExpNormalChar | +| test.cpp:174:23:174:23 | a | RegExpConstant,RegExpNormalChar | +| test.cpp:174:23:174:24 | a+ | RegExpPlus | +| test.cpp:174:23:174:25 | a+b | RegExpSequence | +| test.cpp:174:25:174:25 | b | RegExpConstant,RegExpNormalChar | +| test.cpp:177:24:177:25 | \\s | RegExpCharacterClassEscape | +| test.cpp:177:24:177:26 | \\s+ | RegExpPlus | +| test.cpp:177:24:177:27 | \\s+$ | RegExpSequence | +| test.cpp:177:27:177:27 | $ | RegExpDollar | +| test.cpp:180:24:180:25 | \\( | RegExpConstant,RegExpEscape | +| test.cpp:180:24:180:37 | \\(([,\\w]+)+\\)$ | RegExpSequence | +| test.cpp:180:26:180:33 | ([,\\w]+) | RegExpGroup | +| test.cpp:180:26:180:34 | ([,\\w]+)+ | RegExpPlus | +| test.cpp:180:27:180:31 | [,\\w] | RegExpCharacterClass | +| test.cpp:180:27:180:32 | [,\\w]+ | RegExpPlus | +| test.cpp:180:28:180:28 | , | RegExpConstant,RegExpNormalChar | +| test.cpp:180:29:180:30 | \\w | RegExpCharacterClassEscape | +| test.cpp:180:35:180:36 | \\) | RegExpConstant,RegExpEscape | +| test.cpp:180:37:180:37 | $ | RegExpDollar | +| test.cpp:183:25:183:25 | a | RegExpConstant,RegExpNormalChar | +| test.cpp:183:25:183:26 | a+ | RegExpPlus | +| test.cpp:183:25:183:27 | a+b | RegExpSequence | +| test.cpp:183:27:183:27 | b | RegExpConstant,RegExpNormalChar | +| test.cpp:186:24:186:24 | a | RegExpConstant,RegExpNormalChar | +| test.cpp:186:24:186:25 | a+ | RegExpPlus | +| test.cpp:186:24:186:26 | a+b | RegExpSequence | +| test.cpp:186:26:186:26 | b | RegExpConstant,RegExpNormalChar | +| test.cpp:189:30:189:30 | a | RegExpConstant,RegExpNormalChar | +| test.cpp:189:30:189:31 | a+ | RegExpPlus | +| test.cpp:189:30:189:32 | a+b | RegExpSequence | +| test.cpp:189:32:189:32 | b | RegExpConstant,RegExpNormalChar | +| test.cpp:193:22:193:23 | \\s | RegExpCharacterClassEscape | +| test.cpp:193:22:193:24 | \\s+ | RegExpPlus | +| test.cpp:196:22:196:22 | a | RegExpConstant,RegExpNormalChar | +| test.cpp:196:22:196:25 | a\\.b | RegExpSequence | +| test.cpp:196:23:196:24 | \\. | RegExpConstant,RegExpEscape | +| test.cpp:196:25:196:25 | b | RegExpConstant,RegExpNormalChar | regExpNormalCharValue | test.cpp:33:21:33:23 | abc | abc | | test.cpp:36:22:36:22 | a | a | @@ -320,23 +377,36 @@ regExpNormalCharValue | test.cpp:128:27:128:27 | F | F | | test.cpp:128:37:128:37 | a | a | | test.cpp:128:39:128:39 | f | f | -| test.cpp:136:21:136:26 | \\u9879 | \u9879 | -| test.cpp:144:23:144:23 | a | a | -| test.cpp:144:25:144:25 | b | b | -| test.cpp:147:23:147:23 | a | a | -| test.cpp:147:25:147:25 | b | b | -| test.cpp:150:24:150:25 | \\s | s | -| test.cpp:153:24:153:25 | \\( | ( | -| test.cpp:153:28:153:28 | , | , | -| test.cpp:153:29:153:30 | \\w | w | -| test.cpp:153:35:153:36 | \\) | ) | -| test.cpp:156:25:156:25 | a | a | -| test.cpp:156:27:156:27 | b | b | -| test.cpp:159:24:159:24 | a | a | -| test.cpp:159:26:159:26 | b | b | -| test.cpp:162:30:162:30 | a | a | -| test.cpp:162:32:162:32 | b | b | -| test.cpp:166:22:166:23 | \\s | s | -| test.cpp:169:22:169:22 | a | a | -| test.cpp:169:23:169:24 | \\. | . | -| test.cpp:169:25:169:25 | b | b | +| test.cpp:137:24:137:24 | a | a | +| test.cpp:137:30:137:30 | c | c | +| test.cpp:140:34:140:34 | - | - | +| test.cpp:140:35:140:35 | z | z | +| test.cpp:143:25:143:25 | [ | [ | +| test.cpp:143:26:143:26 | : | : | +| test.cpp:143:27:143:27 | a | a | +| test.cpp:143:28:143:28 | l | l | +| test.cpp:143:29:143:29 | p | p | +| test.cpp:143:30:143:30 | h | h | +| test.cpp:143:31:143:31 | a | a | +| test.cpp:146:25:146:25 | ] | ] | +| test.cpp:146:26:146:26 | a | a | +| test.cpp:163:21:163:26 | \\u9879 | \u9879 | +| test.cpp:171:23:171:23 | a | a | +| test.cpp:171:25:171:25 | b | b | +| test.cpp:174:23:174:23 | a | a | +| test.cpp:174:25:174:25 | b | b | +| test.cpp:177:24:177:25 | \\s | s | +| test.cpp:180:24:180:25 | \\( | ( | +| test.cpp:180:28:180:28 | , | , | +| test.cpp:180:29:180:30 | \\w | w | +| test.cpp:180:35:180:36 | \\) | ) | +| test.cpp:183:25:183:25 | a | a | +| test.cpp:183:27:183:27 | b | b | +| test.cpp:186:24:186:24 | a | a | +| test.cpp:186:26:186:26 | b | b | +| test.cpp:189:30:189:30 | a | a | +| test.cpp:189:32:189:32 | b | b | +| test.cpp:193:22:193:23 | \\s | s | +| test.cpp:196:22:196:22 | a | a | +| test.cpp:196:23:196:24 | \\. | . | +| test.cpp:196:25:196:25 | b | b | diff --git a/cpp/ql/test/library-tests/regex/test.cpp b/cpp/ql/test/library-tests/regex/test.cpp index 7f503a79bfe..37cb61d4a63 100644 --- a/cpp/ql/test/library-tests/regex/test.cpp +++ b/cpp/ql/test/library-tests/regex/test.cpp @@ -130,6 +130,33 @@ void test() { // *Not* a POSIX bracket expression; just a regular character class. std::regex r_posix4("[:digit:]"); + // POSIX-looking but not nested — a plain class with `:`, `a`, `l`, `p`, `h` + std::regex r_posix5("[:alpha:]"); + + // POSIX-looking tokens mid-pattern, not a real POSIX class + std::regex r_posix6("a[:b:]c"); + + // POSIX class as a range endpoint + std::regex r_posix7("[[:alpha:]-z]"); + + // Malformed — missing closing colon + std::regex r_posix8("[[:alpha]"); + + // Leading literal `]` combined with a POSIX class + std::regex r_posix9("[]a[:alpha:]]"); + + // Three POSIX classes in one class + std::regex r_posix10("[[:alpha:][:digit:][:space:]]"); + + // Additional POSIX class names + std::regex r_posix11("[[:xdigit:]]"); + std::regex r_posix12("[[:blank:]]"); + std::regex r_posix13("[[:cntrl:]]"); + std::regex r_posix14("[[:graph:]]"); + + // Integration case + std::regex r_posix15("^([[:alpha:]]+[[:digit:]]*[[:space:]]?)+([[:punct:]]|[[:xdigit:]])+$"); + // Dropped: /#{A}bc/ — Ruby string interpolation, no C++ string-literal form. // unicode: \uHHHH 4-digit hex form (valid ECMAScript \u escape in std::regex)