Skip to content

Commit d7a8f48

Browse files
authored
Commit 3: Add test.cpp corpus wrapped in std::regex stubs; generate .expected
Introduces cpp/ql/test/library-tests/regex/test.cpp with the Ruby regex corpus mechanically translated to C++ string literals and wrapped in std::regex construction calls using fully self-contained in-file stubs (no #include of any external/standard header). Stub surface: std::basic_regex<CharT> constructor(const char*), constructor(const char*, int), assign(const char*) std::regex typedef for basic_regex<char> std::regex_match / regex_search / regex_replace free functions 1:1 corpus mapping from regexp.rb: - All Ruby /regex/ literals translated to C++ "string" literals (each backslash doubled: /\d/ -> "\\d") - Dropped: /#{A}bc/ (Ruby string interpolation, no string-literal form) - Kept: a{,8}, .*m, \A, \z, \G, \h\H, (?'foo'...) — these are removed in commits 4 and 5 (keeping them here preserves 1:1 mapping) Also removes `abstract` from RegExp class in ParseRegExp.qll so that all StringLiterals are regex candidates (trivial syntactic gate; no dataflow). .expected generated by: codeql test run --learn --search-path=. cpp/ql/test/library-tests/regex/ (CodeQL CLI 2.26.1, bundled C/C++ extractor) All 2 tests passed.
1 parent 52b35ef commit d7a8f48

4 files changed

Lines changed: 867 additions & 1 deletion

File tree

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,12 @@ private import semmle.code.cpp.exprs.Literal
1111
* A C++ string literal that contains a regular expression term, that is, either
1212
* a regular expression literal, or a string literal used in a context where
1313
* it is parsed as a regular expression.
14+
*
15+
* All string literals are considered potential regexes for now. Future work
16+
* will restrict this to only string literals actually used as regular
17+
* expressions (via construction-site flow analysis).
1418
*/
15-
abstract class RegExp extends StringLiteral {
19+
class RegExp extends StringLiteral {
1620
/**
1721
* Holds if this `RegExp` has the `s` flag for multi-line matching.
1822
*/

0 commit comments

Comments
 (0)