From fd28416b0cd6463e5151bc5da66ce6229e8dd773 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 23 Jul 2026 09:55:13 +0000 Subject: [PATCH 01/26] Initial plan From 07449054ccb43cfefe83284d3e8946a94b7393e3 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 21 Jul 2026 10:01:38 +0000 Subject: [PATCH 02/26] C++: Copy Ruby regex library and tests verbatim --- .../semmle/code/cpp/regex/RegexTreeView.qll | 1235 +++++++++++++++++ .../code/cpp/regex/internal/ParseRegExp.qll | 1037 ++++++++++++++ .../test/library-tests/regex/parse.expected | 489 +++++++ cpp/ql/test/library-tests/regex/parse.ql | 27 + .../test/library-tests/regex/regexp.expected | 270 ++++ cpp/ql/test/library-tests/regex/regexp.ql | 11 + cpp/ql/test/library-tests/regex/regexp.rb | 82 ++ 7 files changed, 3151 insertions(+) create mode 100644 cpp/ql/lib/semmle/code/cpp/regex/RegexTreeView.qll create mode 100644 cpp/ql/lib/semmle/code/cpp/regex/internal/ParseRegExp.qll create mode 100644 cpp/ql/test/library-tests/regex/parse.expected create mode 100644 cpp/ql/test/library-tests/regex/parse.ql create mode 100644 cpp/ql/test/library-tests/regex/regexp.expected create mode 100644 cpp/ql/test/library-tests/regex/regexp.ql create mode 100644 cpp/ql/test/library-tests/regex/regexp.rb diff --git a/cpp/ql/lib/semmle/code/cpp/regex/RegexTreeView.qll b/cpp/ql/lib/semmle/code/cpp/regex/RegexTreeView.qll new file mode 100644 index 000000000000..51df17008817 --- /dev/null +++ b/cpp/ql/lib/semmle/code/cpp/regex/RegexTreeView.qll @@ -0,0 +1,1235 @@ +/** Provides a class hierarchy corresponding to a parse tree of regular expressions. */ + +private import internal.ParseRegExp +private import codeql.util.Numbers +private import codeql.ruby.ast.Literal as Ast +private import codeql.Locations +private import codeql.regex.nfa.NfaUtils as NfaUtils +private import codeql.regex.RegexTreeView +// exporting as RegexTreeView, and in the top-level scope. +import Impl as RegexTreeView +import Impl + +/** Gets the parse tree resulting from parsing `re`, if such has been constructed. */ +RegExpTerm getParsedRegExp(Ast::RegExpLiteral re) { + result.getRegExp() = re and result.isRootTerm() +} + +/** + * An element containing a regular expression term, that is, either + * a string literal (parsed as a regular expression) + * or another regular expression term. + * + * For sequences and alternations, we require at least one child. + * Otherwise, we wish to represent the term differently. + * This avoids multiple representations of the same term. + */ +private newtype TRegExpParent = + /** A string literal used as a regular expression */ + TRegExpLiteral(RegExp re) or + /** A quantified term */ + TRegExpQuantifier(RegExp re, int start, int end) { re.qualifiedItem(start, end, _, _) } or + /** A sequence term */ + TRegExpSequence(RegExp re, int start, int end) { re.sequence(start, end) } or + /** An alternation term */ + TRegExpAlt(RegExp re, int start, int end) { re.alternation(start, end) } or + /** A character class term */ + TRegExpCharacterClass(RegExp re, int start, int end) { re.charSet(start, end) } or + /** A character range term */ + TRegExpCharacterRange(RegExp re, int start, int end) { re.charRange(_, start, _, _, end) } or + /** A group term */ + TRegExpGroup(RegExp re, int start, int end) { re.group(start, end) } or + /** A special character */ + TRegExpSpecialChar(RegExp re, int start, int end) { re.specialCharacter(start, end, _) } or + /** A normal character */ + TRegExpNormalChar(RegExp re, int start, int end) { + re.normalCharacterSequence(start, end) + or + re.escapedCharacter(start, end) and + not re.specialCharacter(start, end, _) + } or + /** A back reference */ + TRegExpBackRef(RegExp re, int start, int end) { re.backreference(start, end) } or + /** A named character property */ + TRegExpNamedCharacterProperty(RegExp re, int start, int end) { + re.namedCharacterProperty(start, end, _) + } + +/** An implementation that statisfies the RegexTreeView signature. */ +private module Impl implements RegexTreeViewSig { + /** + * An element containing a regular expression term, that is, either + * a string literal (parsed as a regular expression) + * or another regular expression term. + */ + class RegExpParent extends TRegExpParent { + /** Gets a textual representation of this element. */ + string toString() { result = "RegExpParent" } + + /** Gets the `i`th child term. */ + RegExpTerm getChild(int i) { none() } + + /** Gets a child term . */ + final RegExpTerm getAChild() { result = this.getChild(_) } + + /** Gets the number of child terms. */ + int getNumChild() { result = count(this.getAChild()) } + + /** Gets the last child term of this element. */ + RegExpTerm getLastChild() { result = this.getChild(this.getNumChild() - 1) } + + /** + * Gets the name of a primary CodeQL class to which this regular + * expression term belongs. + */ + string getAPrimaryQlClass() { result = "RegExpParent" } + + /** + * Gets a comma-separated list of the names of the primary CodeQL classes to + * which this regular expression term belongs. + */ + final string getPrimaryQlClasses() { result = concat(this.getAPrimaryQlClass(), ",") } + } + + /** A string literal used as a regular expression */ + class RegExpLiteral extends TRegExpLiteral, RegExpParent { + RegExp re; + + RegExpLiteral() { this = TRegExpLiteral(re) } + + override RegExpTerm getChild(int i) { + i = 0 and result.getRegExp() = re and result.isRootTerm() + } + + /** Holds if dot, `.`, matches all characters, including newlines. */ + predicate isDotAll() { re.isDotAll() } + + /** Holds if this regex matching is case-insensitive for this regex. */ + predicate isIgnoreCase() { re.isIgnoreCase() } + + /** Get a string representing all modes for this regex. */ + string getFlags() { result = re.getFlags() } + + /** Gets the primary QL class for this regex. */ + override string getAPrimaryQlClass() { result = "RegExpLiteral" } + } + + /** + * A regular expression term, that is, a syntactic part of a regular expression. + */ + class RegExpTerm extends RegExpParent { + RegExp re; + int start; + int end; + + RegExpTerm() { + this = TRegExpAlt(re, start, end) + or + this = TRegExpBackRef(re, start, end) + or + this = TRegExpCharacterClass(re, start, end) + or + this = TRegExpCharacterRange(re, start, end) + or + this = TRegExpNormalChar(re, start, end) + or + this = TRegExpGroup(re, start, end) + or + this = TRegExpQuantifier(re, start, end) + or + this = TRegExpSequence(re, start, end) and + exists(seqChild(re, start, end, 1)) // if a sequence does not have more than one element, it should be treated as that element instead. + or + this = TRegExpSpecialChar(re, start, end) + or + this = TRegExpNamedCharacterProperty(re, start, end) + } + + /** + * Gets the outermost term of this regular expression. + */ + RegExpTerm getRootTerm() { + this.isRootTerm() and result = this + or + result = this.getParent().(RegExpTerm).getRootTerm() + } + + /** + * Holds if this term is part of a string literal + * that is interpreted as a regular expression. + */ + predicate isUsedAsRegExp() { any() } + + /** + * Holds if this is the root term of a regular expression. + */ + predicate isRootTerm() { start = 0 and end = re.getText().length() } + + override RegExpTerm getChild(int i) { + result = this.(RegExpAlt).getChild(i) + or + result = this.(RegExpBackRef).getChild(i) + or + result = this.(RegExpCharacterClass).getChild(i) + or + result = this.(RegExpCharacterRange).getChild(i) + or + result = this.(RegExpNormalChar).getChild(i) + or + result = this.(RegExpGroup).getChild(i) + or + result = this.(RegExpQuantifier).getChild(i) + or + result = this.(RegExpSequence).getChild(i) + or + result = this.(RegExpSpecialChar).getChild(i) + or + result = this.(RegExpNamedCharacterProperty).getChild(i) + } + + /** + * Gets the parent term of this regular expression term, or the + * regular expression literal if this is the root term. + */ + RegExpParent getParent() { result.getAChild() = this } + + /** Gets the associated `RegExp`. */ + RegExp getRegExp() { result = re } + + /** Gets the offset at which this term starts. */ + int getStart() { result = start } + + /** Gets the offset at which this term ends. */ + int getEnd() { result = end } + + override string toString() { result = re.getText().substring(start, end) } + + /** + * Gets the location of the surrounding regex, as locations inside the regex do not exist. + * To get location information corresponding to the term inside the regex, + * use `hasLocationInfo`. + */ + Location getLocation() { result = re.getLocation() } + + pragma[noinline] + private predicate componentHasLocationInfo( + int i, string filepath, int startline, int startcolumn, int endline, int endcolumn + ) { + re.getComponent(i) + .getLocation() + .hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn) + } + + /** Holds if this term is found at the specified location offsets. */ + predicate hasLocationInfo( + string filepath, int startline, int startcolumn, int endline, int endcolumn + ) { + exists(int re_start | + this.componentHasLocationInfo(0, filepath, startline, re_start, _, _) and + this.componentHasLocationInfo(re.getNumberOfComponents() - 1, filepath, _, _, endline, _) and + startcolumn = re_start + start and + endcolumn = re_start + end - 1 + ) + } + + /** Gets the file in which this term is found. */ + File getFile() { result = this.getLocation().getFile() } + + /** Gets the raw source text of this term. */ + string getRawValue() { result = this.toString() } + + /** Gets the string literal in which this term is found. */ + RegExpLiteral getLiteral() { result = TRegExpLiteral(re) } + + /** Gets the regular expression term that is matched (textually) before this one, if any. */ + RegExpTerm getPredecessor() { + exists(RegExpTerm parent | parent = this.getParent() | + result = parent.(RegExpSequence).previousElement(this) + or + not exists(parent.(RegExpSequence).previousElement(this)) and + not parent instanceof RegExpSubPattern and + result = parent.getPredecessor() + ) + } + + /** Gets the regular expression term that is matched (textually) after this one, if any. */ + RegExpTerm getSuccessor() { + exists(RegExpTerm parent | parent = this.getParent() | + result = parent.(RegExpSequence).nextElement(this) + or + not exists(parent.(RegExpSequence).nextElement(this)) and + not parent instanceof RegExpSubPattern and + result = parent.getSuccessor() + ) + } + + /** + * Gets the single string this regular-expression term matches. + * + * This predicate is only defined for (sequences/groups of) constant regular + * expressions. In particular, terms involving zero-width assertions like `^` + * or `\b` are not considered to have a constant value. + * + * Note that this predicate does not take flags of the enclosing + * regular-expression literal into account. + */ + string getConstantValue() { none() } + + /** + * Gets a string that is matched by this regular-expression term. + */ + string getAMatchedString() { result = this.getConstantValue() } + + /** Gets the primary QL class for this term. */ + override string getAPrimaryQlClass() { result = "RegExpTerm" } + + /** Holds if this regular expression term can match the empty string. */ + predicate isNullable() { none() } + } + + /** + * A quantified regular expression term. + * + * Example: + * + * ``` + * ((ECMA|Java)[sS]cript)* + * ``` + */ + class RegExpQuantifier extends RegExpTerm, TRegExpQuantifier { + int part_end; + boolean may_repeat_forever; + + RegExpQuantifier() { + this = TRegExpQuantifier(re, start, end) and + re.qualifiedPart(start, part_end, end, _, may_repeat_forever) + } + + override RegExpTerm getChild(int i) { + i = 0 and + result.getRegExp() = re and + result.getStart() = start and + result.getEnd() = part_end + } + + /** Hols if this term may match an unlimited number of times. */ + predicate mayRepeatForever() { may_repeat_forever = true } + + /** Gets the qualifier for this term. That is e.g "?" for "a?". */ + string getQualifier() { result = re.getText().substring(part_end, end) } + + override string getAPrimaryQlClass() { result = "RegExpQuantifier" } + } + + /** + * A regular expression term that permits unlimited repetitions. + */ + class InfiniteRepetitionQuantifier extends RegExpQuantifier { + InfiniteRepetitionQuantifier() { this.mayRepeatForever() } + + override string getAPrimaryQlClass() { result = "InfiniteRepetitionQuantifier" } + } + + /** + * A star-quantified term. + * + * Example: + * + * ``` + * \w* + * ``` + */ + class RegExpStar extends InfiniteRepetitionQuantifier { + RegExpStar() { this.getQualifier().charAt(0) = "*" } + + override string getAPrimaryQlClass() { result = "RegExpStar" } + + override predicate isNullable() { any() } + } + + /** + * A plus-quantified term. + * + * Example: + * + * ``` + * \w+ + * ``` + */ + class RegExpPlus extends InfiniteRepetitionQuantifier { + RegExpPlus() { this.getQualifier().charAt(0) = "+" } + + override string getAPrimaryQlClass() { result = "RegExpPlus" } + + override predicate isNullable() { this.getAChild().isNullable() } + } + + /** + * An optional term. + * + * Example: + * + * ``` + * ;? + * ``` + */ + class RegExpOpt extends RegExpQuantifier { + RegExpOpt() { this.getQualifier().charAt(0) = "?" } + + override string getAPrimaryQlClass() { result = "RegExpOpt" } + + override predicate isNullable() { any() } + } + + /** + * A range-quantified term + * + * Examples: + * + * ``` + * \w{2,4} + * \w{2,} + * \w{2} + * ``` + */ + class RegExpRange extends RegExpQuantifier { + string upper; + string lower; + + RegExpRange() { re.multiples(part_end, end, lower, upper) } + + override string getAPrimaryQlClass() { result = "RegExpRange" } + + /** Gets the string defining the upper bound of this range, if any. */ + string getUpper() { result = upper } + + /** Gets the string defining the lower bound of this range, if any. */ + string getLower() { result = lower } + + /** + * Gets the upper bound of the range, if any. + * + * If there is no upper bound, any number of repetitions is allowed. + * For a term of the form `r{lo}`, both the lower and the upper bound + * are `lo`. + */ + int getUpperBound() { result = this.getUpper().toInt() } + + /** Gets the lower bound of the range. */ + int getLowerBound() { result = this.getLower().toInt() } + + override predicate isNullable() { this.getAChild().isNullable() or this.getLowerBound() = 0 } + } + + /** + * A sequence term. + * + * Example: + * + * ``` + * (ECMA|Java)Script + * ``` + * + * This is a sequence with the elements `(ECMA|Java)` and `Script`. + */ + class RegExpSequence extends RegExpTerm, TRegExpSequence { + RegExpSequence() { + this = TRegExpSequence(re, start, end) and + exists(seqChild(re, start, end, 1)) // if a sequence does not have more than one element, it should be treated as that element instead. + } + + override RegExpTerm getChild(int i) { result = seqChild(re, start, end, i) } + + /** Gets the element preceding `element` in this sequence. */ + RegExpTerm previousElement(RegExpTerm element) { element = this.nextElement(result) } + + /** Gets the element following `element` in this sequence. */ + RegExpTerm nextElement(RegExpTerm element) { + exists(int i | + element = this.getChild(i) and + result = this.getChild(i + 1) + ) + } + + override string getConstantValue() { result = this.getConstantValue(0) } + + /** + * Gets the single string matched by the `i`th child and all following + * children of this sequence, if any. + */ + private string getConstantValue(int i) { + i = this.getNumChild() and + result = "" + or + result = this.getChild(i).getConstantValue() + this.getConstantValue(i + 1) + } + + override string getAPrimaryQlClass() { result = "RegExpSequence" } + + override predicate isNullable() { + forall(RegExpTerm child | child = this.getAChild() | child.isNullable()) + } + } + + pragma[nomagic] + private int seqChildEnd(RegExp re, int start, int end, int i) { + result = seqChild(re, start, end, i).getEnd() + } + + // moved out so we can use it in the charpred + private RegExpTerm seqChild(RegExp re, int start, int end, int i) { + re.sequence(start, end) and + ( + i = 0 and + result.getRegExp() = re and + result.getStart() = start and + exists(int itemEnd | + re.item(start, itemEnd) and + result.getEnd() = itemEnd + ) + or + i > 0 and + result.getRegExp() = re and + exists(int itemStart | itemStart = seqChildEnd(re, start, end, i - 1) | + result.getStart() = itemStart and + re.item(itemStart, result.getEnd()) + ) + ) + } + + /** + * An alternative term, that is, a term of the form `a|b`. + * + * Example: + * + * ``` + * ECMA|Java + * ``` + */ + class RegExpAlt extends RegExpTerm, TRegExpAlt { + RegExpAlt() { this = TRegExpAlt(re, start, end) } + + override RegExpTerm getChild(int i) { + i = 0 and + result.getRegExp() = re and + result.getStart() = start and + exists(int part_end | + re.alternationOption(start, end, start, part_end) and + result.getEnd() = part_end + ) + or + i > 0 and + result.getRegExp() = re and + exists(int part_start | + part_start = this.getChild(i - 1).getEnd() + 1 // allow for the | + | + result.getStart() = part_start and + re.alternationOption(start, end, part_start, result.getEnd()) + ) + } + + /** Gets an alternative of this term. */ + RegExpTerm getAlternative() { result = this.getAChild() } + + override string getAMatchedString() { result = this.getAlternative().getAMatchedString() } + + override string getAPrimaryQlClass() { result = "RegExpAlt" } + + override predicate isNullable() { this.getAChild().isNullable() } + } + + /** + * A character escape in a regular expression. + * + * Example: + * + * ``` + * \. + * ``` + */ + class RegExpCharEscape = RegExpEscape; + + /** + * An escaped regular expression term, that is, a regular expression + * term starting with a backslash, which is not a backreference. + * + * Example: + * + * ``` + * \. + * \w + * ``` + */ + class RegExpEscape extends RegExpNormalChar { + RegExpEscape() { re.escapedCharacter(start, end) } + + /** + * Gets the name of the escaped; for example, `w` for `\w`. + * TODO: Handle named escapes. + */ + override string getValue() { + not this.isUnicode() and + this.isIdentityEscape() and + result = this.getUnescaped() + or + this.getUnescaped() = "n" and result = "\n" + or + this.getUnescaped() = "r" and result = "\r" + or + this.getUnescaped() = "t" and result = "\t" + or + this.getUnescaped() = "f" and result = 12.toUnicode() + or + this.getUnescaped() = "v" and result = 11.toUnicode() + or + this.isUnicode() and + result = this.getUnicode() + } + + /** Holds if this terms name is given by the part following the escape character. */ + predicate isIdentityEscape() { + not this.getUnescaped() in ["n", "r", "t", "f", "v"] and not this.isUnicode() + } + + override string getAPrimaryQlClass() { result = "RegExpEscape" } + + /** Gets the part of the term following the escape character. That is e.g. "w" if the term is "\w". */ + string getUnescaped() { result = this.getText().suffix(1) } + + /** + * Gets the text for this escape. That is e.g. "\w". + */ + private string getText() { result = re.getText().substring(start, end) } + + /** + * Holds if this is a unicode escape. + */ + private predicate isUnicode() { this.getText().prefix(2) = ["\\u", "\\U"] } + + /** + * Gets the unicode char for this escape. + * E.g. for `\u0061` this returns "a". + */ + private string getUnicode() { + this.isUnicode() and + result = parseHexInt(this.getText().suffix(2)).toUnicode() + } + } + + /** + * A word boundary, that is, a regular expression term of the form `\b`. + */ + class RegExpWordBoundary extends RegExpSpecialChar { + RegExpWordBoundary() { this.getChar() = "\\b" } + + override predicate isNullable() { none() } + } + + /** + * A non-word boundary, that is, a regular expression term of the form `\B`. + */ + class RegExpNonWordBoundary extends RegExpSpecialChar { + RegExpNonWordBoundary() { this.getChar() = "\\B" } + + override string getAPrimaryQlClass() { result = "RegExpNonWordBoundary" } + } + + /** + * A character class escape in a regular expression. + * That is, an escaped character that denotes multiple characters. + * + * Examples: + * + * ``` + * \w + * \S + * ``` + */ + class RegExpCharacterClassEscape extends RegExpEscape { + RegExpCharacterClassEscape() { this.getValue() in ["d", "D", "s", "S", "w", "W", "h", "H"] } + + override RegExpTerm getChild(int i) { none() } + + override string getAPrimaryQlClass() { result = "RegExpCharacterClassEscape" } + + override predicate isNullable() { none() } + } + + /** + * A character class in a regular expression. + * + * Examples: + * + * ```rb + * /[a-fA-F0-9]/ + * /[^abc]/ + * ``` + */ + class RegExpCharacterClass extends RegExpTerm, TRegExpCharacterClass { + RegExpCharacterClass() { this = TRegExpCharacterClass(re, start, end) } + + /** Holds if this character class is inverted, matching the opposite of its content. */ + predicate isInverted() { re.getChar(start + 1) = "^" } + + /** Holds if this character class can match anything. */ + predicate isUniversalClass() { + // [^] + this.isInverted() and not exists(this.getAChild()) + or + // [\w\W] and similar + not this.isInverted() and + exists(string cce1, string cce2 | + cce1 = this.getAChild().(RegExpCharacterClassEscape).getValue() and + cce2 = this.getAChild().(RegExpCharacterClassEscape).getValue() + | + cce1 != cce2 and cce1.toLowerCase() = cce2.toLowerCase() + ) + } + + override RegExpTerm getChild(int i) { + i = 0 and + result.getRegExp() = re and + exists(int itemStart, int itemEnd | + result.getStart() = itemStart and + re.charSetStart(start, itemStart) and + re.charSetChild(start, itemStart, itemEnd) and + result.getEnd() = itemEnd + ) + or + i > 0 and + result.getRegExp() = re and + exists(int itemStart | itemStart = this.getChild(i - 1).getEnd() | + result.getStart() = itemStart and + re.charSetChild(start, itemStart, result.getEnd()) + ) + } + + override string getAMatchedString() { + not this.isInverted() and result = this.getAChild().getAMatchedString() + } + + override string getAPrimaryQlClass() { result = "RegExpCharacterClass" } + + override predicate isNullable() { none() } + } + + /** + * A character range in a character class in a regular expression. + * + * Example: + * + * ``` + * a-z + * ``` + */ + class RegExpCharacterRange extends RegExpTerm, TRegExpCharacterRange { + int lower_end; + int upper_start; + + RegExpCharacterRange() { + this = TRegExpCharacterRange(re, start, end) and + re.charRange(_, start, lower_end, upper_start, end) + } + + /** Holds if this range goes from `lo` to `hi`, in effect is `lo-hi`. */ + predicate isRange(string lo, string hi) { + lo = re.getText().substring(start, lower_end) and + hi = re.getText().substring(upper_start, end) + } + + override RegExpTerm getChild(int i) { + i = 0 and + result.getRegExp() = re and + result.getStart() = start and + result.getEnd() = lower_end + or + i = 1 and + result.getRegExp() = re and + result.getStart() = upper_start and + result.getEnd() = end + } + + override string getAPrimaryQlClass() { result = "RegExpCharacterRange" } + + override predicate isNullable() { none() } + } + + /** + * A normal character in a regular expression, that is, a character + * without special meaning. This includes escaped characters. + * + * Examples: + * ``` + * t + * \t + * ``` + */ + additional class RegExpNormalChar extends RegExpTerm, TRegExpNormalChar { + RegExpNormalChar() { this = TRegExpNormalChar(re, start, end) } + + /** + * Holds if this constant represents a valid Unicode character (as opposed + * to a surrogate code point that does not correspond to a character by itself.) + */ + predicate isCharacter() { any() } + + /** Gets the string representation of the char matched by this term. */ + string getValue() { result = re.getText().substring(start, end) } + + override RegExpTerm getChild(int i) { none() } + + override string getAPrimaryQlClass() { result = "RegExpNormalChar" } + } + + /** + * A constant regular expression term, that is, a regular expression + * term matching a single string. Currently, this will always be a single character. + * + * Example: + * + * ``` + * a + * ``` + */ + class RegExpConstant extends RegExpTerm { + string value; + + RegExpConstant() { + this = TRegExpNormalChar(re, start, end) and + not this instanceof RegExpCharacterClassEscape and + // exclude chars in qualifiers + // TODO: push this into regex library + not exists(int qstart, int qend | re.qualifiedPart(_, qstart, qend, _, _) | + qstart <= start and end <= qend + ) and + value = this.(RegExpNormalChar).getValue() + or + this = TRegExpSpecialChar(re, start, end) and + re.inCharSet(start) and + value = this.(RegExpSpecialChar).getChar() + } + + /** + * Holds if this constant represents a valid Unicode character (as opposed + * to a surrogate code point that does not correspond to a character by itself.) + */ + predicate isCharacter() { any() } + + /** Gets the string matched by this constant term. */ + string getValue() { result = value } + + override RegExpTerm getChild(int i) { none() } + + override string getConstantValue() { result = this.getValue() } + + override string getAPrimaryQlClass() { result = "RegExpConstant" } + + override predicate isNullable() { none() } + } + + /** + * A grouped regular expression. + * + * Examples: + * + * ``` + * (ECMA|Java) + * (?:ECMA|Java) + * (?['"]) + * ``` + */ + class RegExpGroup extends RegExpTerm, TRegExpGroup { + RegExpGroup() { this = TRegExpGroup(re, start, end) } + + /** + * Gets the index of this capture group within the enclosing regular + * expression literal. + * + * For example, in the regular expression `/((a?).)(?:b)/`, the + * group `((a?).)` has index 1, the group `(a?)` nested inside it + * has index 2, and the group `(?:b)` has no index, since it is + * not a capture group. + */ + int getNumber() { result = re.getGroupNumber(start, end) } + + /** Holds if this is a capture group. */ + predicate isCapture() { exists(this.getNumber()) } + + /** Holds if this is a named capture group. */ + predicate isNamed() { exists(this.getName()) } + + /** Gets the name of this capture group, if any. */ + string getName() { result = re.getGroupName(start, end) } + + override RegExpTerm getChild(int i) { + result.getRegExp() = re and + i = 0 and + re.groupContents(start, end, result.getStart(), result.getEnd()) + } + + override string getConstantValue() { result = this.getAChild().getConstantValue() } + + override string getAMatchedString() { result = this.getAChild().getAMatchedString() } + + override string getAPrimaryQlClass() { result = "RegExpGroup" } + + override predicate isNullable() { this.getAChild().isNullable() } + } + + /** + * A special character in a regular expression. + * + * Examples: + * ``` + * ^ + * $ + * . + * ``` + */ + additional class RegExpSpecialChar extends RegExpTerm, TRegExpSpecialChar { + string char; + + RegExpSpecialChar() { + this = TRegExpSpecialChar(re, start, end) and + re.specialCharacter(start, end, char) + } + + /** + * Holds if this constant represents a valid Unicode character (as opposed + * to a surrogate code point that does not correspond to a character by itself.) + */ + predicate isCharacter() { any() } + + /** Gets the char for this term. */ + string getChar() { result = char } + + override RegExpTerm getChild(int i) { none() } + + override string getAPrimaryQlClass() { result = "RegExpSpecialChar" } + } + + /** + * A dot regular expression. + * + * Example: + * + * ``` + * . + * ``` + */ + class RegExpDot extends RegExpSpecialChar { + RegExpDot() { this.getChar() = "." } + + override string getAPrimaryQlClass() { result = "RegExpDot" } + + override predicate isNullable() { none() } + } + + /** + * A term that matches a specific position between characters in the string. + * + * Example: + * + * ``` + * \A + * ``` + */ + class RegExpAnchor extends RegExpSpecialChar { + RegExpAnchor() { this.getChar() = ["^", "$", "\\A", "\\Z", "\\z"] } + + override string getAPrimaryQlClass() { result = "RegExpAnchor" } + } + + /** + * A dollar assertion `$` or `\Z` matching the end of a line. + * + * Example: + * + * ``` + * $ + * ``` + */ + class RegExpDollar extends RegExpAnchor { + RegExpDollar() { this.getChar() = ["$", "\\Z", "\\z"] } + + override string getAPrimaryQlClass() { result = "RegExpDollar" } + + override predicate isNullable() { any() } + } + + /** + * A caret assertion `^` or `\A` matching the beginning of a line. + * + * Example: + * + * ``` + * ^ + * ``` + */ + class RegExpCaret extends RegExpAnchor { + RegExpCaret() { this.getChar() = ["^", "\\A"] } + + override string getAPrimaryQlClass() { result = "RegExpCaret" } + + override predicate isNullable() { any() } + } + + /** + * A zero-width match, that is, either an empty group or an assertion. + * + * Examples: + * ``` + * () + * (?=\w) + * ``` + */ + additional class RegExpZeroWidthMatch extends RegExpGroup { + RegExpZeroWidthMatch() { re.zeroWidthMatch(start, end) } + + override RegExpTerm getChild(int i) { none() } + + override string getAPrimaryQlClass() { result = "RegExpZeroWidthMatch" } + + override predicate isNullable() { any() } + } + + /** + * A zero-width lookahead or lookbehind assertion. + * + * Examples: + * + * ``` + * (?=\w) + * (?!\n) + * (?<=\.) + * (?` + * in a regular expression. + * + * Examples: + * + * ``` + * \1 + * (?P=quote) + * ``` + */ + class RegExpBackRef extends RegExpTerm, TRegExpBackRef { + RegExpBackRef() { this = TRegExpBackRef(re, start, end) } + + /** + * Gets the number of the capture group this back reference refers to, if any. + */ + int getNumber() { result = re.getBackRefNumber(start, end) } + + /** + * Gets the name of the capture group this back reference refers to, if any. + */ + string getName() { result = re.getBackRefName(start, end) } + + /** Gets the capture group this back reference refers to. */ + RegExpGroup getGroup() { + result.getLiteral() = this.getLiteral() and + ( + result.getNumber() = this.getNumber() or + result.getName() = this.getName() + ) + } + + override RegExpTerm getChild(int i) { none() } + + override string getAPrimaryQlClass() { result = "RegExpBackRef" } + + override predicate isNullable() { this.getGroup().isNullable() } + } + + /** + * A named character property. For example, the POSIX bracket expression + * `[[:digit:]]`. + */ + additional class RegExpNamedCharacterProperty extends RegExpTerm, TRegExpNamedCharacterProperty { + RegExpNamedCharacterProperty() { this = TRegExpNamedCharacterProperty(re, start, end) } + + override RegExpTerm getChild(int i) { none() } + + override string getAPrimaryQlClass() { result = "RegExpNamedCharacterProperty" } + + /** + * Gets the property name. For example, in `\p{Space}`, the result is + * `"Space"`. + */ + string getName() { result = re.getCharacterPropertyName(start, end) } + + /** + * Holds if the property is inverted. For example, it holds for `\p{^Digit}`, + * which matches non-digits. + */ + predicate isInverted() { re.namedCharacterPropertyIsInverted(start, end) } + } + + class Top = RegExpParent; + + /** + * Holds if `term` is an escape class representing e.g. `\d`. + * `clazz` is which character class it represents, e.g. "d" for `\d`. + */ + predicate isEscapeClass(RegExpTerm term, string clazz) { + exists(RegExpCharacterClassEscape escape | term = escape | escape.getValue() = clazz) + or + // TODO: expand to cover more properties + exists(RegExpNamedCharacterProperty escape | term = escape | + escape.getName().toLowerCase() = "digit" and + if escape.isInverted() then clazz = "D" else clazz = "d" + or + escape.getName().toLowerCase() = "space" and + if escape.isInverted() then clazz = "S" else clazz = "s" + or + escape.getName().toLowerCase() = "word" and + if escape.isInverted() then clazz = "W" else clazz = "w" + ) + } + + /** + * Holds if the regular expression should not be considered. + */ + predicate isExcluded(RegExpParent parent) { + parent.(RegExpTerm).getRegExp().(Ast::RegExpLiteral).hasFreeSpacingFlag() // exclude free-spacing mode regexes + } + + /** + * Holds if `term` is a possessive quantifier. + * Not currently implemented, but is used by the shared library. + */ + predicate isPossessive(RegExpQuantifier term) { none() } + + /** + * Holds if the regex that `term` is part of is used in a way that ignores any leading prefix of the input it's matched against. + * Not yet implemented for Ruby. + */ + predicate matchesAnyPrefix(RegExpTerm term) { any() } + + /** + * Holds if the regex that `term` is part of is used in a way that ignores any trailing suffix of the input it's matched against. + * Not yet implemented for Ruby. + */ + predicate matchesAnySuffix(RegExpTerm term) { any() } + + /** + * Holds if `root` has the `i` flag for case-insensitive matching. + */ + predicate isIgnoreCase(RegExpTerm root) { + root.isRootTerm() and + root.getLiteral().isIgnoreCase() + } + + /** + * Holds if `root` has the `s` flag for multi-line matching. + */ + predicate isDotAll(RegExpTerm root) { + root.isRootTerm() and + root.getLiteral().isDotAll() + } +} diff --git a/cpp/ql/lib/semmle/code/cpp/regex/internal/ParseRegExp.qll b/cpp/ql/lib/semmle/code/cpp/regex/internal/ParseRegExp.qll new file mode 100644 index 000000000000..d35d9353bf13 --- /dev/null +++ b/cpp/ql/lib/semmle/code/cpp/regex/internal/ParseRegExp.qll @@ -0,0 +1,1037 @@ +/** + * Library for parsing for Ruby regular expressions. + * + * N.B. does not yet handle stripping whitespace and comments in regexes with + * the `x` (free-spacing) flag. + */ + +private import codeql.ruby.AST as Ast +private import codeql.Locations + +/** + * A `StringlikeLiteral` containing a regular expression term, that is, either + * a regular expression literal, or a string literal used in a context where + * it is parsed as regular expression. + */ +abstract class RegExp extends Ast::StringlikeLiteral { + /** + * Holds if this `RegExp` has the `s` flag for multi-line matching. + */ + predicate isDotAll() { none() } + + /** + * Holds if this `RegExp` has the `i` flag for case-insensitive matching. + */ + predicate isIgnoreCase() { none() } + + /** + * Gets the flags for this `RegExp`, or the empty string if it has no flags. + */ + string getFlags() { result = "" } + + /** + * Helper predicate for `charSetStart(int start, int end)`. + * + * In order to identify left brackets ('[') which actually start a character class, + * we perform a left to right scan of the string. + * + * To avoid negative recursion we return a boolean. See `escaping`, + * the helper for `escapingChar`, for a clean use of this pattern. + * + * result is true for those start chars that actually mark a start of a char set. + */ + boolean charSetStart(int pos) { + exists(int index | + // is opening bracket + this.charSetDelimiter(index, pos) = true and + ( + // if this is the first bracket, `pos` starts a char set + index = 1 and result = true + or + // if the previous char set delimiter was not a closing bracket, `pos` does + // not start a char set. This is needed to handle cases such as `[[]` (a + // char set that matches the `[` char) + index > 1 and + not this.charSetDelimiter(index - 1, _) = false and + result = false + or + // special handling of cases such as `[][]` (the character-set of the characters `]` and `[`). + exists(int prevClosingBracketPos | + // previous bracket is a closing bracket + this.charSetDelimiter(index - 1, prevClosingBracketPos) = false and + if + // check if the character that comes before the previous closing bracket + // is an opening bracket (taking `^` into account) + // check if the character that comes before the previous closing bracket + // is an opening bracket (taking `^` into account) + exists(int posBeforePrevClosingBracket | + if this.getChar(prevClosingBracketPos - 1) = "^" + then posBeforePrevClosingBracket = prevClosingBracketPos - 2 + else posBeforePrevClosingBracket = prevClosingBracketPos - 1 + | + this.charSetDelimiter(index - 2, posBeforePrevClosingBracket) = true + ) + then + // brackets without anything in between is not valid character ranges, so + // the first closing bracket in `[]]` and `[^]]` does not count, + // + // and we should _not_ mark the second opening bracket in `[][]` and `[^][]` + // as starting a new char set. ^ ^ + exists(int posBeforePrevClosingBracket | + this.charSetDelimiter(index - 2, posBeforePrevClosingBracket) = true + | + result = this.charSetStart(posBeforePrevClosingBracket).booleanNot() + ) + else + // if not, `pos` does in fact mark a real start of a character range + result = true + ) + ) + ) + } + + /** + * Helper predicate for chars that could be character-set delimiters. + * Holds if the (non-escaped) char at `pos` in the string, is the (one-based) `index` occurrence of a bracket (`[` or `]`) in the string. + * Result if `true` is the char is `[`, and `false` if the char is `]`. + */ + boolean charSetDelimiter(int index, int pos) { + pos = + rank[index](int p | + (this.nonEscapedCharAt(p) = "[" or this.nonEscapedCharAt(p) = "]") and + // Brackets that art part of POSIX expressions should not count as + // char-set delimiters. + not exists(int x, int y | + this.posixStyleNamedCharacterProperty(x, y, _) and pos >= x and pos < y + ) + ) and + ( + this.nonEscapedCharAt(pos) = "[" and result = true + or + this.nonEscapedCharAt(pos) = "]" and result = false + ) + } + + /** Holds if a character set starts between `start` and `end`. */ + predicate charSetStart(int start, int end) { + this.charSetStart(start) = true and + ( + this.getChar(start + 1) = "^" and end = start + 2 + or + not this.getChar(start + 1) = "^" and end = start + 1 + ) + } + + /** Whether there is a character class, between start (inclusive) and end (exclusive) */ + predicate charSet(int start, int end) { + exists(int innerStart, int innerEnd | + this.charSetStart(start, innerStart) and + not this.charSetStart(_, start) + | + end = innerEnd + 1 and + innerEnd = + min(int e | + e > innerStart and + this.nonEscapedCharAt(e) = "]" and + not exists(int x, int y | + this.posixStyleNamedCharacterProperty(x, y, _) and e >= x and e < y + ) + | + e + ) + ) + } + + /** + * Holds if the character set starting at `charsetStart` contains either + * a character or a `-` found between `start` and `end`. + */ + private predicate charSetToken(int charsetStart, int index, int tokenStart, int tokenEnd) { + tokenStart = + rank[index](int start, int end | this.charSetToken(charsetStart, start, end) | start) and + this.charSetToken(charsetStart, tokenStart, tokenEnd) + } + + /** + * Holds if the character set starting at `charsetStart` contains either + * a character or a `-` found between `start` and `end`. + */ + private predicate charSetToken(int charsetStart, int start, int end) { + this.charSetStart(charsetStart, start) and + ( + this.escapedCharacter(start, end) + or + this.namedCharacterProperty(start, end, _) + or + exists(this.nonEscapedCharAt(start)) and end = start + 1 + ) + or + this.charSetToken(charsetStart, _, start) and + ( + this.escapedCharacter(start, end) + or + this.namedCharacterProperty(start, end, _) + or + exists(this.nonEscapedCharAt(start)) and + end = start + 1 and + not this.getChar(start) = "]" + ) + } + + /** + * Holds if the character set starting at `charsetStart` contains either + * a character or a range found between `start` and `end`. + */ + predicate charSetChild(int charsetStart, int start, int end) { + this.charSetToken(charsetStart, start, end) and + not exists(int rangeStart, int rangeEnd | + this.charRange(charsetStart, rangeStart, _, _, rangeEnd) and + rangeStart <= start and + rangeEnd >= end + ) + or + this.charRange(charsetStart, start, _, _, end) + } + + /** + * Holds if the character set starting at `charsetStart` contains a character range + * with lower bound found between `start` and `lowerEnd` + * and upper bound found between `upperStart` and `end`. + */ + predicate charRange(int charsetStart, int start, int lowerEnd, int upperStart, int end) { + exists(int index | + this.charRangeEnd(charsetStart, index) = true and + this.charSetToken(charsetStart, index - 2, start, lowerEnd) and + this.charSetToken(charsetStart, index, upperStart, end) + ) + } + + /** + * Helper predicate for `charRange`. + * We can determine where character ranges end by a left to right sweep. + * + * To avoid negative recursion we return a boolean. See `escaping`, + * the helper for `escapingChar`, for a clean use of this pattern. + */ + private boolean charRangeEnd(int charsetStart, int index) { + this.charSetToken(charsetStart, index, _, _) and + ( + index in [1, 2] and result = false + or + index > 2 and + exists(int connectorStart | + this.charSetToken(charsetStart, index - 1, connectorStart, _) and + this.nonEscapedCharAt(connectorStart) = "-" and + result = + this.charRangeEnd(charsetStart, index - 2) + .booleanNot() + .booleanAnd(this.charRangeEnd(charsetStart, index - 1).booleanNot()) + ) + or + not exists(int connectorStart | + this.charSetToken(charsetStart, index - 1, connectorStart, _) and + this.nonEscapedCharAt(connectorStart) = "-" + ) and + result = false + ) + } + + /** Holds if the character at `pos` is a "\" that is actually escaping what comes after. */ + predicate escapingChar(int pos) { this.escaping(pos) = true } + + /** + * Helper predicate for `escapingChar`. + * In order to avoid negative recursion, we return a boolean. + * This way, we can refer to `escaping(pos - 1).booleanNot()` + * rather than to a negated version of `escaping(pos)`. + */ + private boolean escaping(int pos) { + pos = -1 and result = false + or + this.getChar(pos) = "\\" and result = this.escaping(pos - 1).booleanNot() + or + this.getChar(pos) != "\\" and result = false + } + + /** Gets the text of this regex */ + string getText() { + exists(Ast::ConstantValue c | c = this.getConstantValue() | + result = [this.getConstantValue().getString(), this.getConstantValue().getRegExp()] + ) + } + + /** Gets the `i`th character of this regex */ + string getChar(int i) { result = this.getText().charAt(i) } + + /** Gets the `i`th character of this regex, unless it is part of a character escape sequence. */ + string nonEscapedCharAt(int i) { + result = this.getText().charAt(i) and + not exists(int x, int y | this.escapedCharacter(x, y) and i in [x .. y - 1]) + } + + private predicate isOptionDivider(int i) { this.nonEscapedCharAt(i) = "|" } + + private predicate isGroupEnd(int i) { this.nonEscapedCharAt(i) = ")" and not this.inCharSet(i) } + + private predicate isGroupStart(int i) { this.nonEscapedCharAt(i) = "(" and not this.inCharSet(i) } + + /** + * Holds if the `i`th character could not be parsed. + */ + predicate failedToParse(int i) { + exists(this.getChar(i)) and + not exists(int start, int end | + this.topLevel(start, end) and + start <= i and + end > i + ) + } + + /** Matches named character properties such as `\p{Word}` and `[[:digit:]]` */ + predicate namedCharacterProperty(int start, int end, string name) { + this.pStyleNamedCharacterProperty(start, end, name) or + this.posixStyleNamedCharacterProperty(start, end, name) + } + + /** Gets the name of the character property in start,end */ + string getCharacterPropertyName(int start, int end) { + this.namedCharacterProperty(start, end, result) + } + + /** Matches a POSIX bracket expression such as `[:alnum:]` within a character class. */ + private predicate posixStyleNamedCharacterProperty(int start, int end, string name) { + this.getChar(start) = "[" and + this.getChar(start + 1) = ":" and + end = + min(int e | + e > start and + this.getChar(e - 2) = ":" and + this.getChar(e - 1) = "]" + | + e + ) and + exists(int nameStart | + this.getChar(start + 2) = "^" and nameStart = start + 3 + or + not this.getChar(start + 2) = "^" and nameStart = start + 2 + | + name = this.getText().substring(nameStart, end - 2) + ) + } + + /** + * Matches named character properties. For example: + * - `\p{Space}` + * - `\P{Digit}` upper-case P means inverted + * - `\p{^Word}` caret also means inverted + * + * These can occur both inside and outside of character classes. + */ + private predicate pStyleNamedCharacterProperty(int start, int end, string name) { + this.escapingChar(start) and + this.getChar(start + 1) in ["p", "P"] and + this.getChar(start + 2) = "{" and + this.getChar(end - 1) = "}" and + end > start and + not exists(int i | start + 2 < i and i < end - 1 | this.getChar(i) = "}") and + exists(int nameStart | + this.getChar(start + 3) = "^" and nameStart = start + 4 + or + not this.getChar(start + 3) = "^" and nameStart = start + 3 + | + name = this.getText().substring(nameStart, end - 1) + ) + } + + /** + * Holds if the named character property is inverted. Examples for which it holds: + * - `\P{Digit}` upper-case P means inverted + * - `\p{^Word}` caret also means inverted + * - `[[:^digit:]]` + * + * Examples for which it doesn't hold: + * - `\p{Word}` + * - `\P{^Space}` - upper-case P and caret cancel each other out + * - `[[:alnum:]]` + */ + predicate namedCharacterPropertyIsInverted(int start, int end) { + this.pStyleNamedCharacterProperty(start, end, _) and + exists(boolean upperP, boolean caret | + (if this.getChar(start + 1) = "P" then upperP = true else upperP = false) and + (if this.getChar(start + 3) = "^" then caret = true else caret = false) + | + upperP.booleanXor(caret) = true + ) + or + this.posixStyleNamedCharacterProperty(start, end, _) and + this.getChar(start + 3) = "^" + } + + /** + * Holds if an escaped character is found between `start` and `end`. + * Escaped characters include hex values, octal values and named escapes, + * but excludes backreferences. + */ + predicate escapedCharacter(int start, int end) { + this.escapingChar(start) and + not this.numberedBackreference(start, _, _) and + not this.namedBackreference(start, _, _) and + not this.pStyleNamedCharacterProperty(start, _, _) and + ( + // hex char \xhh + this.getChar(start + 1) = "x" and end = start + 4 + or + // wide hex char \uhhhh + this.getChar(start + 1) = "u" and end = start + 6 + or + // escape not handled above; update when adding a new case + not this.getChar(start + 1) in ["x", "u"] and + not exists(this.getChar(start + 1).toInt()) and + end = start + 2 + ) + } + + /** + * Holds if the character at `index` is inside a character set. + */ + predicate inCharSet(int index) { + exists(int x, int y | this.charSet(x, y) and index in [x + 1 .. y - 2]) + } + + /** + * Holds if the character at `index` is inside a posix bracket. + */ + predicate inPosixBracket(int index) { + exists(int x, int y | + this.posixStyleNamedCharacterProperty(x, y, _) and index in [x + 1 .. y - 2] + ) + } + + /** + * 'simple' characters are any that don't alter the parsing of the regex. + */ + private predicate simpleCharacter(int start, int end) { + end = start + 1 and + not this.charSet(start, _) and + not this.charSet(_, start + 1) and + not exists(int x, int y | + this.posixStyleNamedCharacterProperty(x, y, _) and + start >= x and + end <= y + ) and + exists(string c | c = this.getChar(start) | + exists(int x, int y, int z | + this.charSet(x, z) and + this.charSetStart(x, y) + | + start = y + or + start = z - 2 + or + start > y and start < z - 2 and not this.charRange(_, _, start, end, _) + ) + or + not this.inCharSet(start) and + not c = "(" and + not c = "[" and + not c = ")" and + not c = "|" and + not this.qualifier(start, _, _, _) + ) + } + + /** + * Holds if a simple or escaped character is found between `start` and `end`. + */ + predicate character(int start, int end) { + ( + this.simpleCharacter(start, end) and + not exists(int x, int y | this.escapedCharacter(x, y) and x <= start and y >= end) + or + this.escapedCharacter(start, end) + ) and + not exists(int x, int y | this.groupStart(x, y) and x <= start and y >= end) and + not exists(int x, int y | this.backreference(x, y) and x <= start and y >= end) and + not exists(int x, int y | + this.pStyleNamedCharacterProperty(x, y, _) and x <= start and y >= end + ) and + not exists(int x, int y | this.multiples(x, y, _, _) and x <= start and y >= end) + } + + /** + * Holds if a normal character is found between `start` and `end`. + */ + predicate normalCharacter(int start, int end) { + end = start + 1 and + this.character(start, end) and + not this.specialCharacter(start, end, _) + } + + /** + * Holds if a special character is found between `start` and `end`. + */ + predicate specialCharacter(int start, int end, string char) { + this.character(start, end) and + not this.inCharSet(start) and + ( + end = start + 1 and + char = this.getChar(start) and + (char = "$" or char = "^" or char = ".") + or + end = start + 2 and + this.escapingChar(start) and + char = this.getText().substring(start, end) and + char = ["\\A", "\\Z", "\\z", "\\G", "\\b", "\\B"] + ) + } + + /** + * Holds if the range [start:end) consists of only 'normal' characters. + */ + predicate normalCharacterSequence(int start, int end) { + // a normal character inside a character set is interpreted on its own + this.normalCharacter(start, end) and + this.inCharSet(start) + or + // a maximal run of normal characters is considered as one constant + exists(int s, int e | + e = max(int i | this.normalCharacterRun(s, i)) and + not this.inCharSet(s) + | + // 'abc' can be considered one constant, but + // 'abc+' has to be broken up into 'ab' and 'c+', + // as the qualifier only applies to 'c'. + if this.qualifier(e, _, _, _) + then + end = e and start = e - 1 + or + end = e - 1 and start = s and start < end + else ( + end = e and + start = s + ) + ) + } + + private predicate normalCharacterRun(int start, int end) { + ( + this.normalCharacterRun(start, end - 1) + or + start = end - 1 and not this.normalCharacter(start - 1, start) + ) and + this.normalCharacter(end - 1, end) + } + + private predicate characterItem(int start, int end) { + this.normalCharacterSequence(start, end) or + this.escapedCharacter(start, end) or + this.specialCharacter(start, end, _) + } + + /** Whether the text in the range `start,end` is a group */ + predicate group(int start, int end) { + this.groupContents(start, end, _, _) + or + this.emptyGroup(start, end) + } + + /** Gets the number of the group in start,end */ + int getGroupNumber(int start, int end) { + this.group(start, end) and + not this.nonCapturingGroupStart(start, _) and + result = + count(int i | this.group(i, _) and i < start and not this.nonCapturingGroupStart(i, _)) + 1 + } + + /** Gets the name, if it has one, of the group in start,end */ + string getGroupName(int start, int end) { + this.group(start, end) and + exists(int nameEnd | + this.namedGroupStart(start, nameEnd) and + result = this.getText().substring(start + 3, nameEnd - 1) + ) + } + + /** Whether the text in the range start, end is a group and can match the empty string. */ + predicate zeroWidthMatch(int start, int end) { + this.emptyGroup(start, end) + or + this.negativeAssertionGroup(start, end) + or + this.positiveLookaheadAssertionGroup(start, end) + or + this.positiveLookbehindAssertionGroup(start, end) + } + + /** Holds if an empty group is found between `start` and `end`. */ + predicate emptyGroup(int start, int end) { + exists(int endm1 | end = endm1 + 1 | + this.groupStart(start, endm1) and + this.isGroupEnd(endm1) + ) + } + + private predicate emptyMatchAtStartGroup(int start, int end) { + this.emptyGroup(start, end) + or + this.negativeAssertionGroup(start, end) + or + this.positiveLookaheadAssertionGroup(start, end) + } + + private predicate emptyMatchAtEndGroup(int start, int end) { + this.emptyGroup(start, end) + or + this.negativeAssertionGroup(start, end) + or + this.positiveLookbehindAssertionGroup(start, end) + } + + private predicate negativeAssertionGroup(int start, int end) { + exists(int inStart | + this.negativeLookaheadAssertionStart(start, inStart) + or + this.negativeLookbehindAssertionStart(start, inStart) + | + this.groupContents(start, end, inStart, _) + ) + } + + /** Holds if a negative lookahead is found between `start` and `end` */ + predicate negativeLookaheadAssertionGroup(int start, int end) { + exists(int inStart | this.negativeLookaheadAssertionStart(start, inStart) | + this.groupContents(start, end, inStart, _) + ) + } + + /** Holds if a negative lookbehind is found between `start` and `end` */ + predicate negativeLookbehindAssertionGroup(int start, int end) { + exists(int inStart | this.negativeLookbehindAssertionStart(start, inStart) | + this.groupContents(start, end, inStart, _) + ) + } + + /** Holds if a positive lookahead is found between `start` and `end` */ + predicate positiveLookaheadAssertionGroup(int start, int end) { + exists(int inStart | this.lookaheadAssertionStart(start, inStart) | + this.groupContents(start, end, inStart, _) + ) + } + + /** Holds if a positive lookbehind is found between `start` and `end` */ + predicate positiveLookbehindAssertionGroup(int start, int end) { + exists(int inStart | this.lookbehindAssertionStart(start, inStart) | + this.groupContents(start, end, inStart, _) + ) + } + + private predicate groupStart(int start, int end) { + this.nonCapturingGroupStart(start, end) + or + this.namedGroupStart(start, end) + or + this.lookaheadAssertionStart(start, end) + or + this.negativeLookaheadAssertionStart(start, end) + or + this.lookbehindAssertionStart(start, end) + or + this.negativeLookbehindAssertionStart(start, end) + or + this.commentGroupStart(start, end) + or + this.simpleGroupStart(start, end) + } + + /** Matches the start of a non-capturing group, e.g. `(?:` */ + private predicate nonCapturingGroupStart(int start, int end) { + this.isGroupStart(start) and + this.getChar(start + 1) = "?" and + this.getChar(start + 2) = [":", "=", "<", "!", "#"] and + end = start + 3 + } + + /** Matches the start of a simple group, e.g. `(a+)`. */ + private predicate simpleGroupStart(int start, int end) { + this.isGroupStart(start) and + this.getChar(start + 1) != "?" and + end = start + 1 + } + + /** + * Matches the start of a named group, such as: + * - `(?\w+)` + * - `(?'name'\w+)` + */ + private predicate namedGroupStart(int start, int end) { + this.isGroupStart(start) and + this.getChar(start + 1) = "?" and + ( + this.getChar(start + 2) = "<" and + not this.getChar(start + 3) = "=" and // (?<=foo) is a positive lookbehind assertion + not this.getChar(start + 3) = "!" and // (? start + 3 and this.getChar(i) = ">") and + end = nameEnd + 1 + ) + or + this.getChar(start + 2) = "'" and + exists(int nameEnd | + nameEnd = min(int i | i > start + 2 and this.getChar(i) = "'") and end = nameEnd + 1 + ) + ) + } + + /** Matches the start of a positive lookahead assertion, i.e. `(?=`. */ + private predicate lookaheadAssertionStart(int start, int end) { + this.isGroupStart(start) and + this.getChar(start + 1) = "?" and + this.getChar(start + 2) = "=" and + end = start + 3 + } + + /** Matches the start of a negative lookahead assertion, i.e. `(?!`. */ + private predicate negativeLookaheadAssertionStart(int start, int end) { + this.isGroupStart(start) and + this.getChar(start + 1) = "?" and + this.getChar(start + 2) = "!" and + end = start + 3 + } + + /** Matches the start of a positive lookbehind assertion, i.e. `(?<=`. */ + private predicate lookbehindAssertionStart(int start, int end) { + this.isGroupStart(start) and + this.getChar(start + 1) = "?" and + this.getChar(start + 2) = "<" and + this.getChar(start + 3) = "=" and + end = start + 4 + } + + /** Matches the start of a negative lookbehind assertion, i.e. `(?`. */ + predicate namedBackreference(int start, int end, string name) { + this.escapingChar(start) and + this.getChar(start + 1) = "k" and + this.getChar(start + 2) = "<" and + exists(int nameEnd | nameEnd = min(int i | i > start + 3 and this.getChar(i) = ">") | + end = nameEnd + 1 and + name = this.getText().substring(start + 3, nameEnd) + ) + } + + /** Matches a numbered backreference, e.g. `\1`. */ + predicate numberedBackreference(int start, int end, int value) { + this.escapingChar(start) and + not this.getChar(start + 1) = "0" and + exists(string text, string svalue, int len | + end = start + len and + text = this.getText() and + len in [2 .. 3] + | + svalue = text.substring(start + 1, start + len) and + value = svalue.toInt() and + not exists(text.substring(start + 1, start + len + 1).toInt()) and + value > 0 + ) + } + + /** Whether the text in the range `start,end` is a back reference */ + predicate backreference(int start, int end) { + this.numberedBackreference(start, end, _) + or + this.namedBackreference(start, end, _) + } + + /** Gets the number of the back reference in start,end */ + int getBackRefNumber(int start, int end) { this.numberedBackreference(start, end, result) } + + /** Gets the name, if it has one, of the back reference in start,end */ + string getBackRefName(int start, int end) { this.namedBackreference(start, end, result) } + + private predicate baseItem(int start, int end) { + this.characterItem(start, end) and + not exists(int x, int y | this.charSet(x, y) and x <= start and y >= end) + or + this.group(start, end) + or + this.charSet(start, end) + or + this.backreference(start, end) + or + this.pStyleNamedCharacterProperty(start, end, _) + } + + private predicate qualifier(int start, int end, boolean maybeEmpty, boolean mayRepeatForever) { + this.shortQualifier(start, end, maybeEmpty, mayRepeatForever) and + not this.getChar(end) = "?" + or + exists(int shortEnd | this.shortQualifier(start, shortEnd, maybeEmpty, mayRepeatForever) | + if this.getChar(shortEnd) = "?" then end = shortEnd + 1 else end = shortEnd + ) + } + + private predicate shortQualifier(int start, int end, boolean maybeEmpty, boolean mayRepeatForever) { + ( + this.getChar(start) = "+" and maybeEmpty = false and mayRepeatForever = true + or + this.getChar(start) = "*" and maybeEmpty = true and mayRepeatForever = true + or + this.getChar(start) = "?" and maybeEmpty = true and mayRepeatForever = false + ) and + end = start + 1 + or + exists(string lower, string upper | + this.multiples(start, end, lower, upper) and + (if lower = "" or lower.toInt() = 0 then maybeEmpty = true else maybeEmpty = false) and + if upper = "" then mayRepeatForever = true else mayRepeatForever = false + ) + } + + /** + * Holds if a repetition quantifier is found between `start` and `end`, + * with the given lower and upper bounds. If a bound is omitted, the corresponding + * string is empty. + */ + predicate multiples(int start, int end, string lower, string upper) { + exists(string text, string match, string inner | + text = this.getText() and + end = start + match.length() and + inner = match.substring(1, match.length() - 1) + | + match = text.regexpFind("\\{[0-9]+\\}", _, start) and + lower = inner and + upper = lower + or + match = text.regexpFind("\\{[0-9]*,[0-9]*\\}", _, start) and + exists(int commaIndex | + commaIndex = inner.indexOf(",") and + lower = inner.prefix(commaIndex) and + upper = inner.suffix(commaIndex + 1) + ) + ) + } + + /** + * Whether the text in the range start,end is a qualified item, where item is a character, + * a character set or a group. + */ + predicate qualifiedItem(int start, int end, boolean maybeEmpty, boolean mayRepeatForever) { + this.qualifiedPart(start, _, end, maybeEmpty, mayRepeatForever) + } + + /** + * Holds if a qualified part is found between `start` and `partEnd` and the qualifier is + * found between `partEnd` and `end`. + * + * `maybeEmpty` is true if the part is optional. + * `mayRepeatForever` is true if the part may be repeated unboundedly. + */ + predicate qualifiedPart( + int start, int partEnd, int end, boolean maybeEmpty, boolean mayRepeatForever + ) { + this.baseItem(start, partEnd) and + this.qualifier(partEnd, end, maybeEmpty, mayRepeatForever) + } + + /** Holds if the range `start`, `end` contains a character, a quantifier, a character set or a group. */ + predicate item(int start, int end) { + this.qualifiedItem(start, end, _, _) + or + this.baseItem(start, end) and not this.qualifier(end, _, _, _) + } + + private predicate subsequence(int start, int end) { + ( + start = 0 or + this.groupStart(_, start) or + this.isOptionDivider(start - 1) + ) and + this.item(start, end) + or + exists(int mid | + this.subsequence(start, mid) and + this.item(mid, end) + ) + } + + /** + * Whether the text in the range start,end is a sequence of 1 or more items, where an item is a character, + * a character set or a group. + */ + predicate sequence(int start, int end) { + this.sequenceOrQualified(start, end) and + not this.qualifiedItem(start, end, _, _) + } + + private predicate sequenceOrQualified(int start, int end) { + this.subsequence(start, end) and + not this.itemStart(end) + } + + private predicate itemStart(int start) { + this.characterItem(start, _) or + this.isGroupStart(start) or + this.charSet(start, _) or + this.backreference(start, _) or + this.namedCharacterProperty(start, _, _) + } + + private predicate itemEnd(int end) { + this.characterItem(_, end) + or + exists(int endm1 | this.isGroupEnd(endm1) and end = endm1 + 1) + or + this.charSet(_, end) + or + this.qualifier(_, end, _, _) + } + + private predicate topLevel(int start, int end) { + this.subalternation(start, end, _) and + not this.isOptionDivider(end) + } + + private predicate subalternation(int start, int end, int itemStart) { + this.sequenceOrQualified(start, end) and + not this.isOptionDivider(start - 1) and + itemStart = start + or + start = end and + not this.itemEnd(start) and + this.isOptionDivider(end) and + itemStart = start + or + exists(int mid | + this.subalternation(start, mid, _) and + this.isOptionDivider(mid) and + itemStart = mid + 1 + | + this.sequenceOrQualified(itemStart, end) + or + not this.itemStart(end) and end = itemStart + ) + } + + /** + * Whether the text in the range start,end is an alternation + */ + predicate alternation(int start, int end) { + not this.inCharSet(start) and + this.topLevel(start, end) and + exists(int less | this.subalternation(start, less, _) and less < end) + } + + /** + * Whether the text in the range start,end is an alternation and the text in partStart, partEnd is one of the + * options in that alternation. + */ + predicate alternationOption(int start, int end, int partStart, int partEnd) { + this.alternation(start, end) and + this.subalternation(start, partEnd, partStart) + } + + /** A part of the regex that may match the start of the string. */ + private predicate firstPart(int start, int end) { + start = 0 and end = this.getText().length() + or + exists(int x | this.firstPart(x, end) | + this.emptyMatchAtStartGroup(x, start) + or + this.qualifiedItem(x, start, true, _) + or + // ^ and \A match the start of the string + this.specialCharacter(x, start, ["^", "\\A"]) + ) + or + exists(int y | this.firstPart(start, y) | + this.item(start, end) + or + this.qualifiedPart(start, end, y, _, _) + ) + or + exists(int x, int y | this.firstPart(x, y) | + this.groupContents(x, y, start, end) + or + this.alternationOption(x, y, start, end) + ) + } + + /** A part of the regex that may match the end of the string. */ + private predicate lastPart(int start, int end) { + start = 0 and end = this.getText().length() + or + exists(int y | this.lastPart(start, y) | + this.emptyMatchAtEndGroup(end, y) + or + this.qualifiedItem(end, y, true, _) + or + // $, \Z, and \z match the end of the string. + this.specialCharacter(end, y, ["$", "\\Z", "\\z"]) + ) + or + this.lastPart(_, end) and + this.item(start, end) + or + exists(int y | this.lastPart(start, y) | this.qualifiedPart(start, end, y, _, _)) + or + exists(int x, int y | this.lastPart(x, y) | + this.groupContents(x, y, start, end) + or + this.alternationOption(x, y, start, end) + ) + } + + /** + * Whether the item at [start, end) is one of the first items + * to be matched. + */ + predicate firstItem(int start, int end) { + ( + this.characterItem(start, end) + or + this.qualifiedItem(start, end, _, _) + or + this.charSet(start, end) + ) and + this.firstPart(start, end) + } + + /** + * Whether the item at [start, end) is one of the last items + * to be matched. + */ + predicate lastItem(int start, int end) { + ( + this.characterItem(start, end) + or + this.qualifiedItem(start, end, _, _) + or + this.charSet(start, end) + ) and + this.lastPart(start, end) + } +} diff --git a/cpp/ql/test/library-tests/regex/parse.expected b/cpp/ql/test/library-tests/regex/parse.expected new file mode 100644 index 000000000000..3df78cdb4fbf --- /dev/null +++ b/cpp/ql/test/library-tests/regex/parse.expected @@ -0,0 +1,489 @@ +regexp.rb: +# 5| [RegExpConstant, RegExpNormalChar] abc + +# 8| [RegExpConstant, RegExpNormalChar] a + +# 8| [RegExpStar] a* +#-----| 0 -> [RegExpConstant, RegExpNormalChar] a + +# 8| [RegExpSequence] a*b+c?d +#-----| 0 -> [RegExpStar] a* +#-----| 1 -> [RegExpPlus] b+ +#-----| 2 -> [RegExpOpt] c? +#-----| 3 -> [RegExpConstant, RegExpNormalChar] d + +# 8| [RegExpConstant, RegExpNormalChar] b + +# 8| [RegExpPlus] b+ +#-----| 0 -> [RegExpConstant, RegExpNormalChar] b + +# 8| [RegExpConstant, RegExpNormalChar] c + +# 8| [RegExpOpt] c? +#-----| 0 -> [RegExpConstant, RegExpNormalChar] c + +# 8| [RegExpConstant, RegExpNormalChar] d + +# 9| [RegExpConstant, RegExpNormalChar] a + +# 9| [RegExpRange] a{4,8} +#-----| 0 -> [RegExpConstant, RegExpNormalChar] a + +# 10| [RegExpConstant, RegExpNormalChar] a + +# 10| [RegExpRange] a{,8} +#-----| 0 -> [RegExpConstant, RegExpNormalChar] a + +# 11| [RegExpConstant, RegExpNormalChar] a + +# 11| [InfiniteRepetitionQuantifier, RegExpRange] a{3,} +#-----| 0 -> [RegExpConstant, RegExpNormalChar] a + +# 12| [RegExpConstant, RegExpNormalChar] a + +# 12| [RegExpRange] a{7} +#-----| 0 -> [RegExpConstant, RegExpNormalChar] a + +# 15| [RegExpConstant, RegExpNormalChar] foo + +# 15| [RegExpAlt] foo|bar +#-----| 0 -> [RegExpConstant, RegExpNormalChar] foo +#-----| 1 -> [RegExpConstant, RegExpNormalChar] bar + +# 15| [RegExpConstant, RegExpNormalChar] bar + +# 18| [RegExpCharacterClass] [abc] +#-----| 0 -> [RegExpConstant, RegExpNormalChar] a +#-----| 1 -> [RegExpConstant, RegExpNormalChar] b +#-----| 2 -> [RegExpConstant, RegExpNormalChar] c + +# 18| [RegExpConstant, RegExpNormalChar] a + +# 18| [RegExpConstant, RegExpNormalChar] b + +# 18| [RegExpConstant, RegExpNormalChar] c + +# 19| [RegExpCharacterClass] [a-fA-F0-9_] +#-----| 0 -> [RegExpCharacterRange] a-f +#-----| 1 -> [RegExpCharacterRange] A-F +#-----| 2 -> [RegExpCharacterRange] 0-9 +#-----| 3 -> [RegExpConstant, RegExpNormalChar] _ + +# 19| [RegExpConstant, RegExpNormalChar] a + +# 19| [RegExpCharacterRange] a-f +#-----| 0 -> [RegExpConstant, RegExpNormalChar] a +#-----| 1 -> [RegExpConstant, RegExpNormalChar] f + +# 19| [RegExpConstant, RegExpNormalChar] f + +# 19| [RegExpConstant, RegExpNormalChar] A + +# 19| [RegExpCharacterRange] A-F +#-----| 0 -> [RegExpConstant, RegExpNormalChar] A +#-----| 1 -> [RegExpConstant, RegExpNormalChar] F + +# 19| [RegExpConstant, RegExpNormalChar] F + +# 19| [RegExpConstant, RegExpNormalChar] 0 + +# 19| [RegExpCharacterRange] 0-9 +#-----| 0 -> [RegExpConstant, RegExpNormalChar] 0 +#-----| 1 -> [RegExpConstant, RegExpNormalChar] 9 + +# 19| [RegExpConstant, RegExpNormalChar] 9 + +# 19| [RegExpConstant, RegExpNormalChar] _ + +# 20| [RegExpCaret] \A + +# 20| [RegExpSequence] \A[+-]?\d+ +#-----| 0 -> [RegExpCaret] \A +#-----| 1 -> [RegExpOpt] [+-]? +#-----| 2 -> [RegExpPlus] \d+ + +# 20| [RegExpCharacterClass] [+-] +#-----| 0 -> [RegExpConstant, RegExpNormalChar] + +#-----| 1 -> [RegExpConstant, RegExpNormalChar] - + +# 20| [RegExpOpt] [+-]? +#-----| 0 -> [RegExpCharacterClass] [+-] + +# 20| [RegExpConstant, RegExpNormalChar] + + +# 20| [RegExpConstant, RegExpNormalChar] - + +# 20| [RegExpCharacterClassEscape] \d + +# 20| [RegExpPlus] \d+ +#-----| 0 -> [RegExpCharacterClassEscape] \d + +# 21| [RegExpCharacterClass] [\w] +#-----| 0 -> [RegExpCharacterClassEscape] \w + +# 21| [RegExpPlus] [\w]+ +#-----| 0 -> [RegExpCharacterClass] [\w] + +# 21| [RegExpCharacterClassEscape] \w + +# 22| [RegExpConstant, RegExpEscape] \[ + +# 22| [RegExpSequence] \[\][123] +#-----| 0 -> [RegExpConstant, RegExpEscape] \[ +#-----| 1 -> [RegExpConstant, RegExpEscape] \] +#-----| 2 -> [RegExpCharacterClass] [123] + +# 22| [RegExpConstant, RegExpEscape] \] + +# 22| [RegExpCharacterClass] [123] +#-----| 0 -> [RegExpConstant, RegExpNormalChar] 1 +#-----| 1 -> [RegExpConstant, RegExpNormalChar] 2 +#-----| 2 -> [RegExpConstant, RegExpNormalChar] 3 + +# 22| [RegExpConstant, RegExpNormalChar] 1 + +# 22| [RegExpConstant, RegExpNormalChar] 2 + +# 22| [RegExpConstant, RegExpNormalChar] 3 + +# 23| [RegExpCharacterClass] [^A-Z] +#-----| 0 -> [RegExpCharacterRange] A-Z + +# 23| [RegExpConstant, RegExpNormalChar] A + +# 23| [RegExpCharacterRange] A-Z +#-----| 0 -> [RegExpConstant, RegExpNormalChar] A +#-----| 1 -> [RegExpConstant, RegExpNormalChar] Z + +# 23| [RegExpConstant, RegExpNormalChar] Z + +# 24| [RegExpCharacterClass] []] +#-----| 0 -> [RegExpConstant, RegExpNormalChar] ] + +# 24| [RegExpConstant, RegExpNormalChar] ] + +# 25| [RegExpCharacterClass] [^]] +#-----| 0 -> [RegExpConstant, RegExpNormalChar] ] + +# 25| [RegExpConstant, RegExpNormalChar] ] + +# 26| [RegExpCharacterClass] [^-] +#-----| 0 -> [RegExpConstant, RegExpNormalChar] - + +# 26| [RegExpConstant, RegExpNormalChar] - + +# 27| [RegExpCharacterClass] [|] +#-----| 0 -> [RegExpConstant, RegExpNormalChar] | + +# 27| [RegExpConstant, RegExpNormalChar] | + +# 30| [RegExpCharacterClass] [[a-f] +#-----| 0 -> [RegExpConstant, RegExpNormalChar] [ +#-----| 1 -> [RegExpCharacterRange] a-f + +# 30| [RegExpSequence] [[a-f]A-F] +#-----| 0 -> [RegExpCharacterClass] [[a-f] +#-----| 1 -> [RegExpConstant, RegExpNormalChar] A-F] + +# 30| [RegExpConstant, RegExpNormalChar] [ + +# 30| [RegExpConstant, RegExpNormalChar] a + +# 30| [RegExpCharacterRange] a-f +#-----| 0 -> [RegExpConstant, RegExpNormalChar] a +#-----| 1 -> [RegExpConstant, RegExpNormalChar] f + +# 30| [RegExpConstant, RegExpNormalChar] f + +# 30| [RegExpConstant, RegExpNormalChar] A-F] + +# 33| [RegExpDot] . + +# 33| [RegExpStar] .* +#-----| 0 -> [RegExpDot] . + +# 34| [RegExpDot] . + +# 34| [RegExpStar] .* +#-----| 0 -> [RegExpDot] . + +# 35| [RegExpCharacterClassEscape] \w + +# 35| [RegExpPlus] \w+ +#-----| 0 -> [RegExpCharacterClassEscape] \w + +# 35| [RegExpSequence] \w+\W +#-----| 0 -> [RegExpPlus] \w+ +#-----| 1 -> [RegExpCharacterClassEscape] \W + +# 35| [RegExpCharacterClassEscape] \W + +# 36| [RegExpCharacterClassEscape] \s + +# 36| [RegExpSequence] \s\S +#-----| 0 -> [RegExpCharacterClassEscape] \s +#-----| 1 -> [RegExpCharacterClassEscape] \S + +# 36| [RegExpCharacterClassEscape] \S + +# 37| [RegExpCharacterClassEscape] \d + +# 37| [RegExpSequence] \d\D +#-----| 0 -> [RegExpCharacterClassEscape] \d +#-----| 1 -> [RegExpCharacterClassEscape] \D + +# 37| [RegExpCharacterClassEscape] \D + +# 38| [RegExpCharacterClassEscape] \h + +# 38| [RegExpSequence] \h\H +#-----| 0 -> [RegExpCharacterClassEscape] \h +#-----| 1 -> [RegExpCharacterClassEscape] \H + +# 38| [RegExpCharacterClassEscape] \H + +# 39| [RegExpConstant, RegExpEscape] \n + +# 39| [RegExpSequence] \n\r\t +#-----| 0 -> [RegExpConstant, RegExpEscape] \n +#-----| 1 -> [RegExpConstant, RegExpEscape] \r +#-----| 2 -> [RegExpConstant, RegExpEscape] \t + +# 39| [RegExpConstant, RegExpEscape] \r + +# 39| [RegExpConstant, RegExpEscape] \t + +# 42| [RegExpSpecialChar] \G + +# 42| [RegExpSequence] \Gabc +#-----| 0 -> [RegExpSpecialChar] \G +#-----| 1 -> [RegExpConstant, RegExpNormalChar] abc + +# 42| [RegExpConstant, RegExpNormalChar] abc + +# 43| [RegExpSpecialChar] \b + +# 43| [RegExpSequence] \b!a\B +#-----| 0 -> [RegExpSpecialChar] \b +#-----| 1 -> [RegExpConstant, RegExpNormalChar] !a +#-----| 2 -> [RegExpNonWordBoundary] \B + +# 43| [RegExpConstant, RegExpNormalChar] !a + +# 43| [RegExpNonWordBoundary] \B + +# 46| [RegExpGroup] (foo) +#-----| 0 -> [RegExpConstant, RegExpNormalChar] foo + +# 46| [RegExpStar] (foo)* +#-----| 0 -> [RegExpGroup] (foo) + +# 46| [RegExpSequence] (foo)*bar +#-----| 0 -> [RegExpStar] (foo)* +#-----| 1 -> [RegExpConstant, RegExpNormalChar] bar + +# 46| [RegExpConstant, RegExpNormalChar] foo + +# 46| [RegExpConstant, RegExpNormalChar] bar + +# 47| [RegExpConstant, RegExpNormalChar] fo + +# 47| [RegExpSequence] fo(o|b)ar +#-----| 0 -> [RegExpConstant, RegExpNormalChar] fo +#-----| 1 -> [RegExpGroup] (o|b) +#-----| 2 -> [RegExpConstant, RegExpNormalChar] ar + +# 47| [RegExpGroup] (o|b) +#-----| 0 -> [RegExpAlt] o|b + +# 47| [RegExpConstant, RegExpNormalChar] o + +# 47| [RegExpAlt] o|b +#-----| 0 -> [RegExpConstant, RegExpNormalChar] o +#-----| 1 -> [RegExpConstant, RegExpNormalChar] b + +# 47| [RegExpConstant, RegExpNormalChar] b + +# 47| [RegExpConstant, RegExpNormalChar] ar + +# 48| [RegExpGroup] (a|b|cd) +#-----| 0 -> [RegExpAlt] a|b|cd + +# 48| [RegExpSequence] (a|b|cd)e +#-----| 0 -> [RegExpGroup] (a|b|cd) +#-----| 1 -> [RegExpConstant, RegExpNormalChar] e + +# 48| [RegExpConstant, RegExpNormalChar] a + +# 48| [RegExpAlt] a|b|cd +#-----| 0 -> [RegExpConstant, RegExpNormalChar] a +#-----| 1 -> [RegExpConstant, RegExpNormalChar] b +#-----| 2 -> [RegExpConstant, RegExpNormalChar] cd + +# 48| [RegExpConstant, RegExpNormalChar] b + +# 48| [RegExpConstant, RegExpNormalChar] cd + +# 48| [RegExpConstant, RegExpNormalChar] e + +# 49| [RegExpGroup] (?::+) +#-----| 0 -> [RegExpPlus] :+ + +# 49| [RegExpSequence] (?::+)\w +#-----| 0 -> [RegExpGroup] (?::+) +#-----| 1 -> [RegExpCharacterClassEscape] \w + +# 49| [RegExpConstant, RegExpNormalChar] : + +# 49| [RegExpPlus] :+ +#-----| 0 -> [RegExpConstant, RegExpNormalChar] : + +# 49| [RegExpCharacterClassEscape] \w + +# 52| [RegExpGroup] (?\w+) +#-----| 0 -> [RegExpPlus] \w+ + +# 52| [RegExpCharacterClassEscape] \w + +# 52| [RegExpPlus] \w+ +#-----| 0 -> [RegExpCharacterClassEscape] \w + +# 53| [RegExpGroup] (?'foo'fo+) +#-----| 0 -> [RegExpSequence] fo+ + +# 53| [RegExpConstant, RegExpNormalChar] f + +# 53| [RegExpSequence] fo+ +#-----| 0 -> [RegExpConstant, RegExpNormalChar] f +#-----| 1 -> [RegExpPlus] o+ + +# 53| [RegExpConstant, RegExpNormalChar] o + +# 53| [RegExpPlus] o+ +#-----| 0 -> [RegExpConstant, RegExpNormalChar] o + +# 56| [RegExpGroup] (a+) +#-----| 0 -> [RegExpPlus] a+ + +# 56| [RegExpSequence] (a+)b+\1 +#-----| 0 -> [RegExpGroup] (a+) +#-----| 1 -> [RegExpPlus] b+ +#-----| 2 -> [RegExpBackRef] \1 + +# 56| [RegExpConstant, RegExpNormalChar] a + +# 56| [RegExpPlus] a+ +#-----| 0 -> [RegExpConstant, RegExpNormalChar] a + +# 56| [RegExpConstant, RegExpNormalChar] b + +# 56| [RegExpPlus] b+ +#-----| 0 -> [RegExpConstant, RegExpNormalChar] b + +# 56| [RegExpBackRef] \1 + +# 57| [RegExpGroup] (?q+) +#-----| 0 -> [RegExpPlus] q+ + +# 57| [RegExpSequence] (?q+)\s+\k+ +#-----| 0 -> [RegExpGroup] (?q+) +#-----| 1 -> [RegExpPlus] \s+ +#-----| 2 -> [RegExpPlus] \k+ + +# 57| [RegExpConstant, RegExpNormalChar] q + +# 57| [RegExpPlus] q+ +#-----| 0 -> [RegExpConstant, RegExpNormalChar] q + +# 57| [RegExpCharacterClassEscape] \s + +# 57| [RegExpPlus] \s+ +#-----| 0 -> [RegExpCharacterClassEscape] \s + +# 57| [RegExpBackRef] \k + +# 57| [RegExpPlus] \k+ +#-----| 0 -> [RegExpBackRef] \k + +# 60| [RegExpNamedCharacterProperty] \p{Word} + +# 60| [RegExpStar] \p{Word}* +#-----| 0 -> [RegExpNamedCharacterProperty] \p{Word} + +# 61| [RegExpNamedCharacterProperty] \P{Digit} + +# 61| [RegExpPlus] \P{Digit}+ +#-----| 0 -> [RegExpNamedCharacterProperty] \P{Digit} + +# 62| [RegExpNamedCharacterProperty] \p{^Alnum} + +# 62| [RegExpRange] \p{^Alnum}{2,3} +#-----| 0 -> [RegExpNamedCharacterProperty] \p{^Alnum} + +# 63| [RegExpCharacterClass] [a-f\p{Digit}] +#-----| 0 -> [RegExpCharacterRange] a-f +#-----| 1 -> [RegExpNamedCharacterProperty] \p{Digit} + +# 63| [RegExpPlus] [a-f\p{Digit}]+ +#-----| 0 -> [RegExpCharacterClass] [a-f\p{Digit}] + +# 63| [RegExpConstant, RegExpNormalChar] a + +# 63| [RegExpCharacterRange] a-f +#-----| 0 -> [RegExpConstant, RegExpNormalChar] a +#-----| 1 -> [RegExpConstant, RegExpNormalChar] f + +# 63| [RegExpConstant, RegExpNormalChar] f + +# 63| [RegExpNamedCharacterProperty] \p{Digit} + +# 66| [RegExpCharacterClass] [[:alpha:]] +#-----| 0 -> [RegExpNamedCharacterProperty] [:alpha:] + +# 66| [RegExpSequence] [[:alpha:]][[:digit:]] +#-----| 0 -> [RegExpCharacterClass] [[:alpha:]] +#-----| 1 -> [RegExpCharacterClass] [[:digit:]] + +# 66| [RegExpNamedCharacterProperty] [:alpha:] + +# 66| [RegExpCharacterClass] [[:digit:]] +#-----| 0 -> [RegExpNamedCharacterProperty] [:digit:] + +# 66| [RegExpNamedCharacterProperty] [:digit:] + +# 69| [RegExpCharacterClass] [[:alpha:][:digit:]] +#-----| 0 -> [RegExpNamedCharacterProperty] [:alpha:] +#-----| 1 -> [RegExpNamedCharacterProperty] [:digit:] + +# 69| [RegExpNamedCharacterProperty] [:alpha:] + +# 69| [RegExpNamedCharacterProperty] [:digit:] + +# 72| [RegExpCharacterClass] [A-F[:digit:]a-f] +#-----| 0 -> [RegExpCharacterRange] A-F +#-----| 1 -> [RegExpNamedCharacterProperty] [:digit:] +#-----| 2 -> [RegExpCharacterRange] a-f + +# 72| [RegExpConstant, RegExpNormalChar] A + +# 72| [RegExpCharacterRange] A-F +#-----| 0 -> [RegExpConstant, RegExpNormalChar] A +#-----| 1 -> [RegExpConstant, RegExpNormalChar] F + +# 72| [RegExpConstant, RegExpNormalChar] F + +# 72| [RegExpNamedCharacterProperty] [:digit:] + +# 72| [RegExpConstant, RegExpNormalChar] a + +# 72| [RegExpCharacterRange] a-f +#-----| 0 -> [RegExpConstant, RegExpNormalChar] a +#-----| 1 -> [RegExpConstant, RegExpNormalChar] f + +# 72| [RegExpConstant, RegExpNormalChar] f + +# 75| [RegExpNamedCharacterProperty] [:digit:] + +# 79| [RegExpConstant, RegExpNormalChar] abc + +# 82| [RegExpConstant, RegExpEscape] \u{987 diff --git a/cpp/ql/test/library-tests/regex/parse.ql b/cpp/ql/test/library-tests/regex/parse.ql new file mode 100644 index 000000000000..9bc804ada4de --- /dev/null +++ b/cpp/ql/test/library-tests/regex/parse.ql @@ -0,0 +1,27 @@ +/** + * @kind graph + */ + +import codeql.Locations +import codeql.ruby.Regexp as RE + +query predicate nodes(RE::RegExpTerm n, string attr, string val) { + attr = "semmle.label" and + val = "[" + concat(n.getAPrimaryQlClass(), ", ") + "] " + n.toString() + or + attr = "semmle.order" and + val = + any(int i | + n = + rank[i](RE::RegExpTerm t, string fp, int sl, int sc, int el, int ec | + t.hasLocationInfo(fp, sl, sc, el, ec) + | + t order by fp, sl, sc, el, ec, t.toString() + ) + ).toString() +} + +query predicate edges(RE::RegExpTerm pred, RE::RegExpTerm succ, string attr, string val) { + attr in ["semmle.label", "semmle.order"] and + val = any(int i | succ = pred.getChild(i)).toString() +} diff --git a/cpp/ql/test/library-tests/regex/regexp.expected b/cpp/ql/test/library-tests/regex/regexp.expected new file mode 100644 index 000000000000..e464b5ce5ea5 --- /dev/null +++ b/cpp/ql/test/library-tests/regex/regexp.expected @@ -0,0 +1,270 @@ +groupName +| regexp.rb:52:2:52:11 | (?\\w+) | id | +| regexp.rb:53:2:53:12 | (?'foo'fo+) | foo | +| regexp.rb:57:2:57:11 | (?q+) | qux | +groupNumber +| regexp.rb:46:2:46:6 | (foo) | 1 | +| regexp.rb:47:4:47:8 | (o\|b) | 1 | +| regexp.rb:48:2:48:9 | (a\|b\|cd) | 1 | +| regexp.rb:53:2:53:12 | (?'foo'fo+) | 1 | +| regexp.rb:56:2:56:5 | (a+) | 1 | +term +| regexp.rb:5:2:5:4 | abc | RegExpConstant,RegExpNormalChar | +| regexp.rb:8:2:8:2 | a | RegExpConstant,RegExpNormalChar | +| regexp.rb:8:2:8:3 | a* | RegExpStar | +| regexp.rb:8:2:8:8 | a*b+c?d | RegExpSequence | +| regexp.rb:8:4:8:4 | b | RegExpConstant,RegExpNormalChar | +| regexp.rb:8:4:8:5 | b+ | RegExpPlus | +| regexp.rb:8:6:8:6 | c | RegExpConstant,RegExpNormalChar | +| regexp.rb:8:6:8:7 | c? | RegExpOpt | +| regexp.rb:8:8:8:8 | d | RegExpConstant,RegExpNormalChar | +| regexp.rb:9:2:9:2 | a | RegExpConstant,RegExpNormalChar | +| regexp.rb:9:2:9:7 | a{4,8} | RegExpRange | +| regexp.rb:10:2:10:2 | a | RegExpConstant,RegExpNormalChar | +| regexp.rb:10:2:10:6 | a{,8} | RegExpRange | +| regexp.rb:11:2:11:2 | a | RegExpConstant,RegExpNormalChar | +| regexp.rb:11:2:11:6 | a{3,} | InfiniteRepetitionQuantifier,RegExpRange | +| regexp.rb:12:2:12:2 | a | RegExpConstant,RegExpNormalChar | +| regexp.rb:12:2:12:5 | a{7} | RegExpRange | +| regexp.rb:15:2:15:4 | foo | RegExpConstant,RegExpNormalChar | +| regexp.rb:15:2:15:8 | foo\|bar | RegExpAlt | +| regexp.rb:15:6:15:8 | bar | RegExpConstant,RegExpNormalChar | +| regexp.rb:18:2:18:6 | [abc] | RegExpCharacterClass | +| regexp.rb:18:3:18:3 | a | RegExpConstant,RegExpNormalChar | +| regexp.rb:18:4:18:4 | b | RegExpConstant,RegExpNormalChar | +| regexp.rb:18:5:18:5 | c | RegExpConstant,RegExpNormalChar | +| regexp.rb:19:2:19:13 | [a-fA-F0-9_] | RegExpCharacterClass | +| regexp.rb:19:3:19:3 | a | RegExpConstant,RegExpNormalChar | +| regexp.rb:19:3:19:5 | a-f | RegExpCharacterRange | +| regexp.rb:19:5:19:5 | f | RegExpConstant,RegExpNormalChar | +| regexp.rb:19:6:19:6 | A | RegExpConstant,RegExpNormalChar | +| regexp.rb:19:6:19:8 | A-F | RegExpCharacterRange | +| regexp.rb:19:8:19:8 | F | RegExpConstant,RegExpNormalChar | +| regexp.rb:19:9:19:9 | 0 | RegExpConstant,RegExpNormalChar | +| regexp.rb:19:9:19:11 | 0-9 | RegExpCharacterRange | +| regexp.rb:19:11:19:11 | 9 | RegExpConstant,RegExpNormalChar | +| regexp.rb:19:12:19:12 | _ | RegExpConstant,RegExpNormalChar | +| regexp.rb:20:2:20:3 | \\A | RegExpCaret | +| regexp.rb:20:2:20:11 | \\A[+-]?\\d+ | RegExpSequence | +| regexp.rb:20:4:20:7 | [+-] | RegExpCharacterClass | +| regexp.rb:20:4:20:8 | [+-]? | RegExpOpt | +| regexp.rb:20:5:20:5 | + | RegExpConstant,RegExpNormalChar | +| regexp.rb:20:6:20:6 | - | RegExpConstant,RegExpNormalChar | +| regexp.rb:20:9:20:10 | \\d | RegExpCharacterClassEscape | +| regexp.rb:20:9:20:11 | \\d+ | RegExpPlus | +| regexp.rb:21:2:21:5 | [\\w] | RegExpCharacterClass | +| regexp.rb:21:2:21:6 | [\\w]+ | RegExpPlus | +| regexp.rb:21:3:21:4 | \\w | RegExpCharacterClassEscape | +| regexp.rb:22:2:22:3 | \\[ | RegExpConstant,RegExpEscape | +| regexp.rb:22:2:22:10 | \\[\\][123] | RegExpSequence | +| regexp.rb:22:4:22:5 | \\] | RegExpConstant,RegExpEscape | +| regexp.rb:22:6:22:10 | [123] | RegExpCharacterClass | +| regexp.rb:22:7:22:7 | 1 | RegExpConstant,RegExpNormalChar | +| regexp.rb:22:8:22:8 | 2 | RegExpConstant,RegExpNormalChar | +| regexp.rb:22:9:22:9 | 3 | RegExpConstant,RegExpNormalChar | +| regexp.rb:23:2:23:7 | [^A-Z] | RegExpCharacterClass | +| regexp.rb:23:4:23:4 | A | RegExpConstant,RegExpNormalChar | +| regexp.rb:23:4:23:6 | A-Z | RegExpCharacterRange | +| regexp.rb:23:6:23:6 | Z | RegExpConstant,RegExpNormalChar | +| regexp.rb:24:2:24:4 | []] | RegExpCharacterClass | +| regexp.rb:24:3:24:3 | ] | RegExpConstant,RegExpNormalChar | +| regexp.rb:25:2:25:5 | [^]] | RegExpCharacterClass | +| regexp.rb:25:4:25:4 | ] | RegExpConstant,RegExpNormalChar | +| regexp.rb:26:2:26:5 | [^-] | RegExpCharacterClass | +| regexp.rb:26:4:26:4 | - | RegExpConstant,RegExpNormalChar | +| regexp.rb:27:2:27:4 | [\|] | RegExpCharacterClass | +| regexp.rb:27:3:27:3 | \| | RegExpConstant,RegExpNormalChar | +| regexp.rb:30:2:30:7 | [[a-f] | RegExpCharacterClass | +| regexp.rb:30:2:30:11 | [[a-f]A-F] | RegExpSequence | +| regexp.rb:30:3:30:3 | [ | RegExpConstant,RegExpNormalChar | +| regexp.rb:30:4:30:4 | a | RegExpConstant,RegExpNormalChar | +| regexp.rb:30:4:30:6 | a-f | RegExpCharacterRange | +| regexp.rb:30:6:30:6 | f | RegExpConstant,RegExpNormalChar | +| regexp.rb:30:8:30:11 | A-F] | RegExpConstant,RegExpNormalChar | +| regexp.rb:33:2:33:2 | . | RegExpDot | +| regexp.rb:33:2:33:3 | .* | RegExpStar | +| regexp.rb:34:2:34:2 | . | RegExpDot | +| regexp.rb:34:2:34:3 | .* | RegExpStar | +| regexp.rb:35:2:35:3 | \\w | RegExpCharacterClassEscape | +| regexp.rb:35:2:35:4 | \\w+ | RegExpPlus | +| regexp.rb:35:2:35:6 | \\w+\\W | RegExpSequence | +| regexp.rb:35:5:35:6 | \\W | RegExpCharacterClassEscape | +| regexp.rb:36:2:36:3 | \\s | RegExpCharacterClassEscape | +| regexp.rb:36:2:36:5 | \\s\\S | RegExpSequence | +| regexp.rb:36:4:36:5 | \\S | RegExpCharacterClassEscape | +| regexp.rb:37:2:37:3 | \\d | RegExpCharacterClassEscape | +| regexp.rb:37:2:37:5 | \\d\\D | RegExpSequence | +| regexp.rb:37:4:37:5 | \\D | RegExpCharacterClassEscape | +| regexp.rb:38:2:38:3 | \\h | RegExpCharacterClassEscape | +| regexp.rb:38:2:38:5 | \\h\\H | RegExpSequence | +| regexp.rb:38:4:38:5 | \\H | RegExpCharacterClassEscape | +| regexp.rb:39:2:39:3 | \\n | RegExpConstant,RegExpEscape | +| regexp.rb:39:2:39:7 | \\n\\r\\t | RegExpSequence | +| regexp.rb:39:4:39:5 | \\r | RegExpConstant,RegExpEscape | +| regexp.rb:39:6:39:7 | \\t | RegExpConstant,RegExpEscape | +| regexp.rb:42:2:42:3 | \\G | RegExpSpecialChar | +| regexp.rb:42:2:42:6 | \\Gabc | RegExpSequence | +| regexp.rb:42:4:42:6 | abc | RegExpConstant,RegExpNormalChar | +| regexp.rb:43:2:43:3 | \\b | RegExpSpecialChar | +| regexp.rb:43:2:43:7 | \\b!a\\B | RegExpSequence | +| regexp.rb:43:4:43:5 | !a | RegExpConstant,RegExpNormalChar | +| regexp.rb:43:6:43:7 | \\B | RegExpNonWordBoundary | +| regexp.rb:46:2:46:6 | (foo) | RegExpGroup | +| regexp.rb:46:2:46:7 | (foo)* | RegExpStar | +| regexp.rb:46:2:46:10 | (foo)*bar | RegExpSequence | +| regexp.rb:46:3:46:5 | foo | RegExpConstant,RegExpNormalChar | +| regexp.rb:46:8:46:10 | bar | RegExpConstant,RegExpNormalChar | +| regexp.rb:47:2:47:3 | fo | RegExpConstant,RegExpNormalChar | +| regexp.rb:47:2:47:10 | fo(o\|b)ar | RegExpSequence | +| regexp.rb:47:4:47:8 | (o\|b) | RegExpGroup | +| regexp.rb:47:5:47:5 | o | RegExpConstant,RegExpNormalChar | +| regexp.rb:47:5:47:7 | o\|b | RegExpAlt | +| regexp.rb:47:7:47:7 | b | RegExpConstant,RegExpNormalChar | +| regexp.rb:47:9:47:10 | ar | RegExpConstant,RegExpNormalChar | +| regexp.rb:48:2:48:9 | (a\|b\|cd) | RegExpGroup | +| regexp.rb:48:2:48:10 | (a\|b\|cd)e | RegExpSequence | +| regexp.rb:48:3:48:3 | a | RegExpConstant,RegExpNormalChar | +| regexp.rb:48:3:48:8 | a\|b\|cd | RegExpAlt | +| regexp.rb:48:5:48:5 | b | RegExpConstant,RegExpNormalChar | +| regexp.rb:48:7:48:8 | cd | RegExpConstant,RegExpNormalChar | +| regexp.rb:48:10:48:10 | e | RegExpConstant,RegExpNormalChar | +| regexp.rb:49:2:49:7 | (?::+) | RegExpGroup | +| regexp.rb:49:2:49:9 | (?::+)\\w | RegExpSequence | +| regexp.rb:49:5:49:5 | : | RegExpConstant,RegExpNormalChar | +| regexp.rb:49:5:49:6 | :+ | RegExpPlus | +| regexp.rb:49:8:49:9 | \\w | RegExpCharacterClassEscape | +| regexp.rb:52:2:52:11 | (?\\w+) | RegExpGroup | +| regexp.rb:52:8:52:9 | \\w | RegExpCharacterClassEscape | +| regexp.rb:52:8:52:10 | \\w+ | RegExpPlus | +| regexp.rb:53:2:53:12 | (?'foo'fo+) | RegExpGroup | +| regexp.rb:53:9:53:9 | f | RegExpConstant,RegExpNormalChar | +| regexp.rb:53:9:53:11 | fo+ | RegExpSequence | +| regexp.rb:53:10:53:10 | o | RegExpConstant,RegExpNormalChar | +| regexp.rb:53:10:53:11 | o+ | RegExpPlus | +| regexp.rb:56:2:56:5 | (a+) | RegExpGroup | +| regexp.rb:56:2:56:9 | (a+)b+\\1 | RegExpSequence | +| regexp.rb:56:3:56:3 | a | RegExpConstant,RegExpNormalChar | +| regexp.rb:56:3:56:4 | a+ | RegExpPlus | +| regexp.rb:56:6:56:6 | b | RegExpConstant,RegExpNormalChar | +| regexp.rb:56:6:56:7 | b+ | RegExpPlus | +| regexp.rb:56:8:56:9 | \\1 | RegExpBackRef | +| regexp.rb:57:2:57:11 | (?q+) | RegExpGroup | +| regexp.rb:57:2:57:22 | (?q+)\\s+\\k+ | RegExpSequence | +| regexp.rb:57:9:57:9 | q | RegExpConstant,RegExpNormalChar | +| regexp.rb:57:9:57:10 | q+ | RegExpPlus | +| regexp.rb:57:12:57:13 | \\s | RegExpCharacterClassEscape | +| regexp.rb:57:12:57:14 | \\s+ | RegExpPlus | +| regexp.rb:57:15:57:21 | \\k | RegExpBackRef | +| regexp.rb:57:15:57:22 | \\k+ | RegExpPlus | +| regexp.rb:60:2:60:9 | \\p{Word} | RegExpNamedCharacterProperty | +| regexp.rb:60:2:60:10 | \\p{Word}* | RegExpStar | +| regexp.rb:61:2:61:10 | \\P{Digit} | RegExpNamedCharacterProperty | +| regexp.rb:61:2:61:11 | \\P{Digit}+ | RegExpPlus | +| regexp.rb:62:2:62:11 | \\p{^Alnum} | RegExpNamedCharacterProperty | +| regexp.rb:62:2:62:16 | \\p{^Alnum}{2,3} | RegExpRange | +| regexp.rb:63:2:63:15 | [a-f\\p{Digit}] | RegExpCharacterClass | +| regexp.rb:63:2:63:16 | [a-f\\p{Digit}]+ | RegExpPlus | +| regexp.rb:63:3:63:3 | a | RegExpConstant,RegExpNormalChar | +| regexp.rb:63:3:63:5 | a-f | RegExpCharacterRange | +| regexp.rb:63:5:63:5 | f | RegExpConstant,RegExpNormalChar | +| regexp.rb:63:6:63:14 | \\p{Digit} | RegExpNamedCharacterProperty | +| regexp.rb:66:2:66:12 | [[:alpha:]] | RegExpCharacterClass | +| regexp.rb:66:2:66:23 | [[:alpha:]][[:digit:]] | RegExpSequence | +| regexp.rb:66:3:66:11 | [:alpha:] | RegExpNamedCharacterProperty | +| regexp.rb:66:13:66:23 | [[:digit:]] | RegExpCharacterClass | +| regexp.rb:66:14:66:22 | [:digit:] | RegExpNamedCharacterProperty | +| regexp.rb:69:2:69:21 | [[:alpha:][:digit:]] | RegExpCharacterClass | +| regexp.rb:69:3:69:11 | [:alpha:] | RegExpNamedCharacterProperty | +| regexp.rb:69:12:69:20 | [:digit:] | RegExpNamedCharacterProperty | +| regexp.rb:72:2:72:18 | [A-F[:digit:]a-f] | RegExpCharacterClass | +| regexp.rb:72:3:72:3 | A | RegExpConstant,RegExpNormalChar | +| regexp.rb:72:3:72:5 | A-F | RegExpCharacterRange | +| regexp.rb:72:5:72:5 | F | RegExpConstant,RegExpNormalChar | +| regexp.rb:72:6:72:14 | [:digit:] | RegExpNamedCharacterProperty | +| regexp.rb:72:15:72:15 | a | RegExpConstant,RegExpNormalChar | +| regexp.rb:72:15:72:17 | a-f | RegExpCharacterRange | +| regexp.rb:72:17:72:17 | f | RegExpConstant,RegExpNormalChar | +| regexp.rb:75:2:75:10 | [:digit:] | RegExpNamedCharacterProperty | +| regexp.rb:79:2:79:4 | abc | RegExpConstant,RegExpNormalChar | +| regexp.rb:82:2:82:7 | \\u{987 | RegExpConstant,RegExpEscape | +regExpNormalCharValue +| regexp.rb:5:2:5:4 | abc | abc | +| regexp.rb:8:2:8:2 | a | a | +| regexp.rb:8:4:8:4 | b | b | +| regexp.rb:8:6:8:6 | c | c | +| regexp.rb:8:8:8:8 | d | d | +| regexp.rb:9:2:9:2 | a | a | +| regexp.rb:10:2:10:2 | a | a | +| regexp.rb:11:2:11:2 | a | a | +| regexp.rb:12:2:12:2 | a | a | +| regexp.rb:15:2:15:4 | foo | foo | +| regexp.rb:15:6:15:8 | bar | bar | +| regexp.rb:18:3:18:3 | a | a | +| regexp.rb:18:4:18:4 | b | b | +| regexp.rb:18:5:18:5 | c | c | +| regexp.rb:19:3:19:3 | a | a | +| regexp.rb:19:5:19:5 | f | f | +| regexp.rb:19:6:19:6 | A | A | +| regexp.rb:19:8:19:8 | F | F | +| regexp.rb:19:9:19:9 | 0 | 0 | +| regexp.rb:19:11:19:11 | 9 | 9 | +| regexp.rb:19:12:19:12 | _ | _ | +| regexp.rb:20:5:20:5 | + | + | +| regexp.rb:20:6:20:6 | - | - | +| regexp.rb:20:9:20:10 | \\d | d | +| regexp.rb:21:3:21:4 | \\w | w | +| regexp.rb:22:2:22:3 | \\[ | [ | +| regexp.rb:22:4:22:5 | \\] | ] | +| regexp.rb:22:7:22:7 | 1 | 1 | +| regexp.rb:22:8:22:8 | 2 | 2 | +| regexp.rb:22:9:22:9 | 3 | 3 | +| regexp.rb:23:4:23:4 | A | A | +| regexp.rb:23:6:23:6 | Z | Z | +| regexp.rb:24:3:24:3 | ] | ] | +| regexp.rb:25:4:25:4 | ] | ] | +| regexp.rb:26:4:26:4 | - | - | +| regexp.rb:27:3:27:3 | \| | \| | +| regexp.rb:30:3:30:3 | [ | [ | +| regexp.rb:30:4:30:4 | a | a | +| regexp.rb:30:6:30:6 | f | f | +| regexp.rb:30:8:30:11 | A-F] | A-F] | +| regexp.rb:35:2:35:3 | \\w | w | +| regexp.rb:35:5:35:6 | \\W | W | +| regexp.rb:36:2:36:3 | \\s | s | +| regexp.rb:36:4:36:5 | \\S | S | +| regexp.rb:37:2:37:3 | \\d | d | +| regexp.rb:37:4:37:5 | \\D | D | +| regexp.rb:38:2:38:3 | \\h | h | +| regexp.rb:38:4:38:5 | \\H | H | +| regexp.rb:39:2:39:3 | \\n | \n | +| regexp.rb:39:4:39:5 | \\r | \r | +| regexp.rb:39:6:39:7 | \\t | \t | +| regexp.rb:42:4:42:6 | abc | abc | +| regexp.rb:43:4:43:5 | !a | !a | +| regexp.rb:46:3:46:5 | foo | foo | +| regexp.rb:46:8:46:10 | bar | bar | +| regexp.rb:47:2:47:3 | fo | fo | +| regexp.rb:47:5:47:5 | o | o | +| regexp.rb:47:7:47:7 | b | b | +| regexp.rb:47:9:47:10 | ar | ar | +| regexp.rb:48:3:48:3 | a | a | +| regexp.rb:48:5:48:5 | b | b | +| regexp.rb:48:7:48:8 | cd | cd | +| regexp.rb:48:10:48:10 | e | e | +| regexp.rb:49:5:49:5 | : | : | +| regexp.rb:49:8:49:9 | \\w | w | +| regexp.rb:52:8:52:9 | \\w | w | +| regexp.rb:53:9:53:9 | f | f | +| regexp.rb:53:10:53:10 | o | o | +| regexp.rb:56:3:56:3 | a | a | +| regexp.rb:56:6:56:6 | b | b | +| regexp.rb:57:9:57:9 | q | q | +| regexp.rb:57:12:57:13 | \\s | s | +| regexp.rb:63:3:63:3 | a | a | +| regexp.rb:63:5:63:5 | f | f | +| regexp.rb:72:3:72:3 | A | A | +| regexp.rb:72:5:72:5 | F | F | +| regexp.rb:72:15:72:15 | a | a | +| regexp.rb:72:17:72:17 | f | f | +| regexp.rb:79:2:79:4 | abc | abc | +| regexp.rb:82:2:82:7 | \\u{987 | \u0987 | diff --git a/cpp/ql/test/library-tests/regex/regexp.ql b/cpp/ql/test/library-tests/regex/regexp.ql new file mode 100644 index 000000000000..90fd09ab1be8 --- /dev/null +++ b/cpp/ql/test/library-tests/regex/regexp.ql @@ -0,0 +1,11 @@ +import codeql.ruby.Regexp + +query predicate groupName(RegExpGroup g, string name) { name = g.getName() } + +query predicate groupNumber(RegExpGroup g, int number) { number = g.getNumber() } + +query predicate term(RegExpTerm term, string c) { c = term.getPrimaryQlClasses() } + +query predicate regExpNormalCharValue(RegExpNormalChar term, string value) { + value = term.getValue() +} diff --git a/cpp/ql/test/library-tests/regex/regexp.rb b/cpp/ql/test/library-tests/regex/regexp.rb new file mode 100644 index 000000000000..a68c4878094f --- /dev/null +++ b/cpp/ql/test/library-tests/regex/regexp.rb @@ -0,0 +1,82 @@ +# Empty +// + +# Basic sequence +/abc/ + +# Repetition +/a*b+c?d/ +/a{4,8}/ +/a{,8}/ +/a{3,}/ +/a{7}/ + +# Alternation +/foo|bar/ + +# Character classes +/[abc]/ +/[a-fA-F0-9_]/ +/\A[+-]?\d+/ +/[\w]+/ +/\[\][123]/ +/[^A-Z]/ +/[]]/ # MRI gives a warning, but accepts this as matching ']' +/[^]]/ # MRI gives a warning, but accepts this as matching anything except ']' +/[^-]/ +/[|]/ + +# Nested character classes +/[[a-f]A-F]/ # BAD - not parsed correctly + +# Meta-character classes +/.*/ +/.*/m +/\w+\W/ +/\s\S/ +/\d\D/ +/\h\H/ +/\n\r\t/ + +# Anchors +/\Gabc/ +/\b!a\B/ + +# Groups +/(foo)*bar/ +/fo(o|b)ar/ +/(a|b|cd)e/ +/(?::+)\w/ # Non-capturing group matching colons + +# Named groups +/(?\w+)/ +/(?'foo'fo+)/ + +# Backreferences +/(a+)b+\1/ +/(?q+)\s+\k+/ + +# Named character properties using the p-style syntax +/\p{Word}*/ +/\P{Digit}+/ +/\p{^Alnum}{2,3}/ +/[a-f\p{Digit}]+/ # Also valid inside character classes + +# Two separate character classes, each containing a single POSIX bracket expression +/[[:alpha:]][[:digit:]]/ + +# A single character class containing two POSIX bracket expressions +/[[:alpha:][:digit:]]/ + +# A single character class containing two ranges and one POSIX bracket expression +/[A-F[:digit:]a-f]/ + +# *Not* a POSIX bracket expression; just a regular character class. +/[:digit:]/ + +# Simple constant interpolation +A = "a" +/#{A}bc/ + +# unicode +/\u{9879}/ \ No newline at end of file From e672fbb84904e3360fd182d246bf639c24ef7ba8 Mon Sep 17 00:00:00 2001 From: Jeroen Ketema Date: Tue, 21 Jul 2026 16:10:30 +0200 Subject: [PATCH 03/26] C++: Make regex library compile --- cpp/ql/lib/qlpack.yml | 1 + .../semmle/code/cpp/regex/RegexTreeView.qll | 44 +++++++------------ .../code/cpp/regex/internal/ParseRegExp.qll | 17 +++---- cpp/ql/test/library-tests/regex/parse.ql | 9 ++-- .../regex/{regexp.rb => regexp.cpp} | 0 cpp/ql/test/library-tests/regex/regexp.ql | 2 +- 6 files changed, 28 insertions(+), 45 deletions(-) rename cpp/ql/test/library-tests/regex/{regexp.rb => regexp.cpp} (100%) diff --git a/cpp/ql/lib/qlpack.yml b/cpp/ql/lib/qlpack.yml index 5f4b92a191fc..775e8c717291 100644 --- a/cpp/ql/lib/qlpack.yml +++ b/cpp/ql/lib/qlpack.yml @@ -10,6 +10,7 @@ dependencies: codeql/mad: ${workspace} codeql/quantum: ${workspace} codeql/rangeanalysis: ${workspace} + codeql/regex: ${workspace} codeql/ssa: ${workspace} codeql/typeflow: ${workspace} codeql/tutorial: ${workspace} diff --git a/cpp/ql/lib/semmle/code/cpp/regex/RegexTreeView.qll b/cpp/ql/lib/semmle/code/cpp/regex/RegexTreeView.qll index 51df17008817..a0a116f2fe01 100644 --- a/cpp/ql/lib/semmle/code/cpp/regex/RegexTreeView.qll +++ b/cpp/ql/lib/semmle/code/cpp/regex/RegexTreeView.qll @@ -1,17 +1,17 @@ -/** Provides a class hierarchy corresponding to a parse tree of regular expressions. */ +/** + * Provides a class hierarchy corresponding to a parse tree of C++ regular expressions. + */ private import internal.ParseRegExp private import codeql.util.Numbers -private import codeql.ruby.ast.Literal as Ast -private import codeql.Locations -private import codeql.regex.nfa.NfaUtils as NfaUtils +private import semmle.code.cpp.exprs.Literal private import codeql.regex.RegexTreeView // exporting as RegexTreeView, and in the top-level scope. import Impl as RegexTreeView import Impl /** Gets the parse tree resulting from parsing `re`, if such has been constructed. */ -RegExpTerm getParsedRegExp(Ast::RegExpLiteral re) { +RegExpTerm getParsedRegExp(StringLiteral re) { result.getRegExp() = re and result.isRootTerm() } @@ -55,7 +55,7 @@ private newtype TRegExpParent = re.namedCharacterProperty(start, end, _) } -/** An implementation that statisfies the RegexTreeView signature. */ +/** An implementation that satisfies the RegexTreeView signature. */ private module Impl implements RegexTreeViewSig { /** * An element containing a regular expression term, that is, either @@ -211,24 +211,14 @@ private module Impl implements RegexTreeViewSig { */ Location getLocation() { result = re.getLocation() } - pragma[noinline] - private predicate componentHasLocationInfo( - int i, string filepath, int startline, int startcolumn, int endline, int endcolumn - ) { - re.getComponent(i) - .getLocation() - .hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn) - } - /** Holds if this term is found at the specified location offsets. */ predicate hasLocationInfo( string filepath, int startline, int startcolumn, int endline, int endcolumn ) { exists(int re_start | - this.componentHasLocationInfo(0, filepath, startline, re_start, _, _) and - this.componentHasLocationInfo(re.getNumberOfComponents() - 1, filepath, _, _, endline, _) and - startcolumn = re_start + start and - endcolumn = re_start + end - 1 + re.getLocation().hasLocationInfo(filepath, startline, re_start, endline, _) and + startcolumn = re_start + 1 + start and + endcolumn = re_start + 1 + end - 1 ) } @@ -312,7 +302,7 @@ private module Impl implements RegexTreeViewSig { result.getEnd() = part_end } - /** Hols if this term may match an unlimited number of times. */ + /** Hodls if this term may match an unlimited number of times. */ predicate mayRepeatForever() { may_repeat_forever = true } /** Gets the qualifier for this term. That is e.g "?" for "a?". */ @@ -660,9 +650,9 @@ private module Impl implements RegexTreeViewSig { * * Examples: * - * ```rb - * /[a-fA-F0-9]/ - * /[^abc]/ + * ```cpp + * "[a-fA-F0-9]" + * "[^abc]" * ``` */ class RegExpCharacterClass extends RegExpTerm, TRegExpCharacterClass { @@ -1195,9 +1185,7 @@ private module Impl implements RegexTreeViewSig { /** * Holds if the regular expression should not be considered. */ - predicate isExcluded(RegExpParent parent) { - parent.(RegExpTerm).getRegExp().(Ast::RegExpLiteral).hasFreeSpacingFlag() // exclude free-spacing mode regexes - } + predicate isExcluded(RegExpParent parent) { none() } /** * Holds if `term` is a possessive quantifier. @@ -1207,13 +1195,13 @@ private module Impl implements RegexTreeViewSig { /** * Holds if the regex that `term` is part of is used in a way that ignores any leading prefix of the input it's matched against. - * Not yet implemented for Ruby. + * Not yet implemented for C++. */ predicate matchesAnyPrefix(RegExpTerm term) { any() } /** * Holds if the regex that `term` is part of is used in a way that ignores any trailing suffix of the input it's matched against. - * Not yet implemented for Ruby. + * Not yet implemented for C++. */ predicate matchesAnySuffix(RegExpTerm term) { any() } diff --git a/cpp/ql/lib/semmle/code/cpp/regex/internal/ParseRegExp.qll b/cpp/ql/lib/semmle/code/cpp/regex/internal/ParseRegExp.qll index d35d9353bf13..d9163bb3af05 100644 --- a/cpp/ql/lib/semmle/code/cpp/regex/internal/ParseRegExp.qll +++ b/cpp/ql/lib/semmle/code/cpp/regex/internal/ParseRegExp.qll @@ -1,19 +1,18 @@ /** - * Library for parsing for Ruby regular expressions. + * Library for parsing for C++ regular expressions. * * N.B. does not yet handle stripping whitespace and comments in regexes with * the `x` (free-spacing) flag. */ -private import codeql.ruby.AST as Ast -private import codeql.Locations +private import semmle.code.cpp.exprs.Literal /** - * A `StringlikeLiteral` containing a regular expression term, that is, either + * A C++ string literal containing a regular expression term, that is, either * a regular expression literal, or a string literal used in a context where - * it is parsed as regular expression. + * it is parsed as a regular expression. */ -abstract class RegExp extends Ast::StringlikeLiteral { +abstract class RegExp extends StringLiteral { /** * Holds if this `RegExp` has the `s` flag for multi-line matching. */ @@ -254,11 +253,7 @@ abstract class RegExp extends Ast::StringlikeLiteral { } /** Gets the text of this regex */ - string getText() { - exists(Ast::ConstantValue c | c = this.getConstantValue() | - result = [this.getConstantValue().getString(), this.getConstantValue().getRegExp()] - ) - } + string getText() { result = this.getValue() } /** Gets the `i`th character of this regex */ string getChar(int i) { result = this.getText().charAt(i) } diff --git a/cpp/ql/test/library-tests/regex/parse.ql b/cpp/ql/test/library-tests/regex/parse.ql index 9bc804ada4de..ba9a04ab9bd7 100644 --- a/cpp/ql/test/library-tests/regex/parse.ql +++ b/cpp/ql/test/library-tests/regex/parse.ql @@ -2,10 +2,9 @@ * @kind graph */ -import codeql.Locations -import codeql.ruby.Regexp as RE +import semmle.code.cpp.regex.RegexTreeView -query predicate nodes(RE::RegExpTerm n, string attr, string val) { +query predicate nodes(RegExpTerm n, string attr, string val) { attr = "semmle.label" and val = "[" + concat(n.getAPrimaryQlClass(), ", ") + "] " + n.toString() or @@ -13,7 +12,7 @@ query predicate nodes(RE::RegExpTerm n, string attr, string val) { val = any(int i | n = - rank[i](RE::RegExpTerm t, string fp, int sl, int sc, int el, int ec | + rank[i](RegExpTerm t, string fp, int sl, int sc, int el, int ec | t.hasLocationInfo(fp, sl, sc, el, ec) | t order by fp, sl, sc, el, ec, t.toString() @@ -21,7 +20,7 @@ query predicate nodes(RE::RegExpTerm n, string attr, string val) { ).toString() } -query predicate edges(RE::RegExpTerm pred, RE::RegExpTerm succ, string attr, string val) { +query predicate edges(RegExpTerm pred, RegExpTerm succ, string attr, string val) { attr in ["semmle.label", "semmle.order"] and val = any(int i | succ = pred.getChild(i)).toString() } diff --git a/cpp/ql/test/library-tests/regex/regexp.rb b/cpp/ql/test/library-tests/regex/regexp.cpp similarity index 100% rename from cpp/ql/test/library-tests/regex/regexp.rb rename to cpp/ql/test/library-tests/regex/regexp.cpp diff --git a/cpp/ql/test/library-tests/regex/regexp.ql b/cpp/ql/test/library-tests/regex/regexp.ql index 90fd09ab1be8..e167cb1a7bb0 100644 --- a/cpp/ql/test/library-tests/regex/regexp.ql +++ b/cpp/ql/test/library-tests/regex/regexp.ql @@ -1,4 +1,4 @@ -import codeql.ruby.Regexp +import semmle.code.cpp.regex.RegexTreeView query predicate groupName(RegExpGroup g, string name) { name = g.getName() } From b91b83381b97395a1c2fe5f5701037c3c262fc9f Mon Sep 17 00:00:00 2001 From: Jeroen Ketema Date: Tue, 21 Jul 2026 16:29:30 +0200 Subject: [PATCH 04/26] C++: Make regex test work Note that we are currently still implementing what Ruby thinks a regex is. This is not correct as C++ by default uses a variant of ECMAScript regexes. We will address this in the follow-up commits. --- .../test/library-tests/regex/parse.expected | 358 ++++++------ cpp/ql/test/library-tests/regex/parse.ql | 6 + cpp/ql/test/library-tests/regex/regexp.cpp | 173 +++--- .../test/library-tests/regex/regexp.expected | 530 +++++++++--------- cpp/ql/test/library-tests/regex/regexp.ql | 6 + 5 files changed, 545 insertions(+), 528 deletions(-) diff --git a/cpp/ql/test/library-tests/regex/parse.expected b/cpp/ql/test/library-tests/regex/parse.expected index 3df78cdb4fbf..13d74f0e5616 100644 --- a/cpp/ql/test/library-tests/regex/parse.expected +++ b/cpp/ql/test/library-tests/regex/parse.expected @@ -1,489 +1,487 @@ -regexp.rb: -# 5| [RegExpConstant, RegExpNormalChar] abc +regexp.cpp: +# 18| [RegExpConstant, RegExpNormalChar] abc -# 8| [RegExpConstant, RegExpNormalChar] a +# 21| [RegExpConstant, RegExpNormalChar] a -# 8| [RegExpStar] a* +# 21| [RegExpStar] a* #-----| 0 -> [RegExpConstant, RegExpNormalChar] a -# 8| [RegExpSequence] a*b+c?d +# 21| [RegExpSequence] a*b+c?d #-----| 0 -> [RegExpStar] a* #-----| 1 -> [RegExpPlus] b+ #-----| 2 -> [RegExpOpt] c? #-----| 3 -> [RegExpConstant, RegExpNormalChar] d -# 8| [RegExpConstant, RegExpNormalChar] b +# 21| [RegExpConstant, RegExpNormalChar] b -# 8| [RegExpPlus] b+ +# 21| [RegExpPlus] b+ #-----| 0 -> [RegExpConstant, RegExpNormalChar] b -# 8| [RegExpConstant, RegExpNormalChar] c +# 21| [RegExpConstant, RegExpNormalChar] c -# 8| [RegExpOpt] c? +# 21| [RegExpOpt] c? #-----| 0 -> [RegExpConstant, RegExpNormalChar] c -# 8| [RegExpConstant, RegExpNormalChar] d +# 21| [RegExpConstant, RegExpNormalChar] d -# 9| [RegExpConstant, RegExpNormalChar] a +# 22| [RegExpConstant, RegExpNormalChar] a -# 9| [RegExpRange] a{4,8} +# 22| [RegExpRange] a{4,8} #-----| 0 -> [RegExpConstant, RegExpNormalChar] a -# 10| [RegExpConstant, RegExpNormalChar] a +# 23| [RegExpConstant, RegExpNormalChar] a -# 10| [RegExpRange] a{,8} +# 23| [RegExpRange] a{,8} #-----| 0 -> [RegExpConstant, RegExpNormalChar] a -# 11| [RegExpConstant, RegExpNormalChar] a +# 24| [RegExpConstant, RegExpNormalChar] a -# 11| [InfiniteRepetitionQuantifier, RegExpRange] a{3,} +# 24| [InfiniteRepetitionQuantifier, RegExpRange] a{3,} #-----| 0 -> [RegExpConstant, RegExpNormalChar] a -# 12| [RegExpConstant, RegExpNormalChar] a +# 25| [RegExpConstant, RegExpNormalChar] a -# 12| [RegExpRange] a{7} +# 25| [RegExpRange] a{7} #-----| 0 -> [RegExpConstant, RegExpNormalChar] a -# 15| [RegExpConstant, RegExpNormalChar] foo +# 28| [RegExpConstant, RegExpNormalChar] foo -# 15| [RegExpAlt] foo|bar +# 28| [RegExpAlt] foo|bar #-----| 0 -> [RegExpConstant, RegExpNormalChar] foo #-----| 1 -> [RegExpConstant, RegExpNormalChar] bar -# 15| [RegExpConstant, RegExpNormalChar] bar +# 28| [RegExpConstant, RegExpNormalChar] bar -# 18| [RegExpCharacterClass] [abc] +# 31| [RegExpCharacterClass] [abc] #-----| 0 -> [RegExpConstant, RegExpNormalChar] a #-----| 1 -> [RegExpConstant, RegExpNormalChar] b #-----| 2 -> [RegExpConstant, RegExpNormalChar] c -# 18| [RegExpConstant, RegExpNormalChar] a +# 31| [RegExpConstant, RegExpNormalChar] a -# 18| [RegExpConstant, RegExpNormalChar] b +# 31| [RegExpConstant, RegExpNormalChar] b -# 18| [RegExpConstant, RegExpNormalChar] c +# 31| [RegExpConstant, RegExpNormalChar] c -# 19| [RegExpCharacterClass] [a-fA-F0-9_] +# 32| [RegExpCharacterClass] [a-fA-F0-9_] #-----| 0 -> [RegExpCharacterRange] a-f #-----| 1 -> [RegExpCharacterRange] A-F #-----| 2 -> [RegExpCharacterRange] 0-9 #-----| 3 -> [RegExpConstant, RegExpNormalChar] _ -# 19| [RegExpConstant, RegExpNormalChar] a +# 32| [RegExpConstant, RegExpNormalChar] a -# 19| [RegExpCharacterRange] a-f +# 32| [RegExpCharacterRange] a-f #-----| 0 -> [RegExpConstant, RegExpNormalChar] a #-----| 1 -> [RegExpConstant, RegExpNormalChar] f -# 19| [RegExpConstant, RegExpNormalChar] f +# 32| [RegExpConstant, RegExpNormalChar] f -# 19| [RegExpConstant, RegExpNormalChar] A +# 32| [RegExpConstant, RegExpNormalChar] A -# 19| [RegExpCharacterRange] A-F +# 32| [RegExpCharacterRange] A-F #-----| 0 -> [RegExpConstant, RegExpNormalChar] A #-----| 1 -> [RegExpConstant, RegExpNormalChar] F -# 19| [RegExpConstant, RegExpNormalChar] F +# 32| [RegExpConstant, RegExpNormalChar] F -# 19| [RegExpConstant, RegExpNormalChar] 0 +# 32| [RegExpConstant, RegExpNormalChar] 0 -# 19| [RegExpCharacterRange] 0-9 +# 32| [RegExpCharacterRange] 0-9 #-----| 0 -> [RegExpConstant, RegExpNormalChar] 0 #-----| 1 -> [RegExpConstant, RegExpNormalChar] 9 -# 19| [RegExpConstant, RegExpNormalChar] 9 +# 32| [RegExpConstant, RegExpNormalChar] 9 -# 19| [RegExpConstant, RegExpNormalChar] _ +# 32| [RegExpConstant, RegExpNormalChar] _ -# 20| [RegExpCaret] \A +# 33| [RegExpCaret] \A -# 20| [RegExpSequence] \A[+-]?\d+ +# 33| [RegExpSequence] \A[+-]?\d+ #-----| 0 -> [RegExpCaret] \A #-----| 1 -> [RegExpOpt] [+-]? #-----| 2 -> [RegExpPlus] \d+ -# 20| [RegExpCharacterClass] [+-] +# 33| [RegExpCharacterClass] [+-] #-----| 0 -> [RegExpConstant, RegExpNormalChar] + #-----| 1 -> [RegExpConstant, RegExpNormalChar] - -# 20| [RegExpOpt] [+-]? +# 33| [RegExpOpt] [+-]? #-----| 0 -> [RegExpCharacterClass] [+-] -# 20| [RegExpConstant, RegExpNormalChar] + +# 33| [RegExpConstant, RegExpNormalChar] + -# 20| [RegExpConstant, RegExpNormalChar] - +# 33| [RegExpConstant, RegExpNormalChar] - -# 20| [RegExpCharacterClassEscape] \d +# 33| [RegExpCharacterClassEscape] \d -# 20| [RegExpPlus] \d+ +# 33| [RegExpPlus] \d+ #-----| 0 -> [RegExpCharacterClassEscape] \d -# 21| [RegExpCharacterClass] [\w] +# 34| [RegExpCharacterClass] [\w] #-----| 0 -> [RegExpCharacterClassEscape] \w -# 21| [RegExpPlus] [\w]+ +# 34| [RegExpPlus] [\w]+ #-----| 0 -> [RegExpCharacterClass] [\w] -# 21| [RegExpCharacterClassEscape] \w +# 34| [RegExpCharacterClassEscape] \w -# 22| [RegExpConstant, RegExpEscape] \[ +# 35| [RegExpConstant, RegExpEscape] \[ -# 22| [RegExpSequence] \[\][123] +# 35| [RegExpSequence] \[\][123] #-----| 0 -> [RegExpConstant, RegExpEscape] \[ #-----| 1 -> [RegExpConstant, RegExpEscape] \] #-----| 2 -> [RegExpCharacterClass] [123] -# 22| [RegExpConstant, RegExpEscape] \] +# 35| [RegExpConstant, RegExpEscape] \] -# 22| [RegExpCharacterClass] [123] +# 35| [RegExpCharacterClass] [123] #-----| 0 -> [RegExpConstant, RegExpNormalChar] 1 #-----| 1 -> [RegExpConstant, RegExpNormalChar] 2 #-----| 2 -> [RegExpConstant, RegExpNormalChar] 3 -# 22| [RegExpConstant, RegExpNormalChar] 1 +# 35| [RegExpConstant, RegExpNormalChar] 1 -# 22| [RegExpConstant, RegExpNormalChar] 2 +# 35| [RegExpConstant, RegExpNormalChar] 2 -# 22| [RegExpConstant, RegExpNormalChar] 3 +# 35| [RegExpConstant, RegExpNormalChar] 3 -# 23| [RegExpCharacterClass] [^A-Z] +# 36| [RegExpCharacterClass] [^A-Z] #-----| 0 -> [RegExpCharacterRange] A-Z -# 23| [RegExpConstant, RegExpNormalChar] A +# 36| [RegExpConstant, RegExpNormalChar] A -# 23| [RegExpCharacterRange] A-Z +# 36| [RegExpCharacterRange] A-Z #-----| 0 -> [RegExpConstant, RegExpNormalChar] A #-----| 1 -> [RegExpConstant, RegExpNormalChar] Z -# 23| [RegExpConstant, RegExpNormalChar] Z +# 36| [RegExpConstant, RegExpNormalChar] Z -# 24| [RegExpCharacterClass] []] +# 37| [RegExpCharacterClass] []] #-----| 0 -> [RegExpConstant, RegExpNormalChar] ] -# 24| [RegExpConstant, RegExpNormalChar] ] +# 37| [RegExpConstant, RegExpNormalChar] ] -# 25| [RegExpCharacterClass] [^]] +# 38| [RegExpCharacterClass] [^]] #-----| 0 -> [RegExpConstant, RegExpNormalChar] ] -# 25| [RegExpConstant, RegExpNormalChar] ] +# 38| [RegExpConstant, RegExpNormalChar] ] -# 26| [RegExpCharacterClass] [^-] +# 39| [RegExpCharacterClass] [^-] #-----| 0 -> [RegExpConstant, RegExpNormalChar] - -# 26| [RegExpConstant, RegExpNormalChar] - +# 39| [RegExpConstant, RegExpNormalChar] - -# 27| [RegExpCharacterClass] [|] +# 40| [RegExpCharacterClass] [|] #-----| 0 -> [RegExpConstant, RegExpNormalChar] | -# 27| [RegExpConstant, RegExpNormalChar] | +# 40| [RegExpConstant, RegExpNormalChar] | -# 30| [RegExpCharacterClass] [[a-f] +# 43| [RegExpCharacterClass] [[a-f] #-----| 0 -> [RegExpConstant, RegExpNormalChar] [ #-----| 1 -> [RegExpCharacterRange] a-f -# 30| [RegExpSequence] [[a-f]A-F] +# 43| [RegExpSequence] [[a-f]A-F] #-----| 0 -> [RegExpCharacterClass] [[a-f] #-----| 1 -> [RegExpConstant, RegExpNormalChar] A-F] -# 30| [RegExpConstant, RegExpNormalChar] [ +# 43| [RegExpConstant, RegExpNormalChar] [ -# 30| [RegExpConstant, RegExpNormalChar] a +# 43| [RegExpConstant, RegExpNormalChar] a -# 30| [RegExpCharacterRange] a-f +# 43| [RegExpCharacterRange] a-f #-----| 0 -> [RegExpConstant, RegExpNormalChar] a #-----| 1 -> [RegExpConstant, RegExpNormalChar] f -# 30| [RegExpConstant, RegExpNormalChar] f +# 43| [RegExpConstant, RegExpNormalChar] f -# 30| [RegExpConstant, RegExpNormalChar] A-F] +# 43| [RegExpConstant, RegExpNormalChar] A-F] -# 33| [RegExpDot] . +# 46| [RegExpDot] . -# 33| [RegExpStar] .* +# 46| [RegExpStar] .* #-----| 0 -> [RegExpDot] . -# 34| [RegExpDot] . +# 47| [RegExpDot] . -# 34| [RegExpStar] .* +# 47| [RegExpStar] .* #-----| 0 -> [RegExpDot] . -# 35| [RegExpCharacterClassEscape] \w +# 48| [RegExpCharacterClassEscape] \w -# 35| [RegExpPlus] \w+ +# 48| [RegExpPlus] \w+ #-----| 0 -> [RegExpCharacterClassEscape] \w -# 35| [RegExpSequence] \w+\W +# 48| [RegExpSequence] \w+\W #-----| 0 -> [RegExpPlus] \w+ #-----| 1 -> [RegExpCharacterClassEscape] \W -# 35| [RegExpCharacterClassEscape] \W +# 48| [RegExpCharacterClassEscape] \W -# 36| [RegExpCharacterClassEscape] \s +# 49| [RegExpCharacterClassEscape] \s -# 36| [RegExpSequence] \s\S +# 49| [RegExpSequence] \s\S #-----| 0 -> [RegExpCharacterClassEscape] \s #-----| 1 -> [RegExpCharacterClassEscape] \S -# 36| [RegExpCharacterClassEscape] \S +# 49| [RegExpCharacterClassEscape] \S -# 37| [RegExpCharacterClassEscape] \d +# 50| [RegExpCharacterClassEscape] \d -# 37| [RegExpSequence] \d\D +# 50| [RegExpSequence] \d\D #-----| 0 -> [RegExpCharacterClassEscape] \d #-----| 1 -> [RegExpCharacterClassEscape] \D -# 37| [RegExpCharacterClassEscape] \D +# 50| [RegExpCharacterClassEscape] \D -# 38| [RegExpCharacterClassEscape] \h +# 51| [RegExpCharacterClassEscape] \h -# 38| [RegExpSequence] \h\H +# 51| [RegExpSequence] \h\H #-----| 0 -> [RegExpCharacterClassEscape] \h #-----| 1 -> [RegExpCharacterClassEscape] \H -# 38| [RegExpCharacterClassEscape] \H +# 51| [RegExpCharacterClassEscape] \H -# 39| [RegExpConstant, RegExpEscape] \n +# 52| [RegExpConstant, RegExpEscape] \n -# 39| [RegExpSequence] \n\r\t +# 52| [RegExpSequence] \n\r\t #-----| 0 -> [RegExpConstant, RegExpEscape] \n #-----| 1 -> [RegExpConstant, RegExpEscape] \r #-----| 2 -> [RegExpConstant, RegExpEscape] \t -# 39| [RegExpConstant, RegExpEscape] \r +# 52| [RegExpConstant, RegExpEscape] \r -# 39| [RegExpConstant, RegExpEscape] \t +# 52| [RegExpConstant, RegExpEscape] \t -# 42| [RegExpSpecialChar] \G +# 55| [RegExpSpecialChar] \G -# 42| [RegExpSequence] \Gabc +# 55| [RegExpSequence] \Gabc #-----| 0 -> [RegExpSpecialChar] \G #-----| 1 -> [RegExpConstant, RegExpNormalChar] abc -# 42| [RegExpConstant, RegExpNormalChar] abc +# 55| [RegExpConstant, RegExpNormalChar] abc -# 43| [RegExpSpecialChar] \b +# 56| [RegExpSpecialChar] \b -# 43| [RegExpSequence] \b!a\B +# 56| [RegExpSequence] \b!a\B #-----| 0 -> [RegExpSpecialChar] \b #-----| 1 -> [RegExpConstant, RegExpNormalChar] !a #-----| 2 -> [RegExpNonWordBoundary] \B -# 43| [RegExpConstant, RegExpNormalChar] !a +# 56| [RegExpConstant, RegExpNormalChar] !a -# 43| [RegExpNonWordBoundary] \B +# 56| [RegExpNonWordBoundary] \B -# 46| [RegExpGroup] (foo) +# 59| [RegExpGroup] (foo) #-----| 0 -> [RegExpConstant, RegExpNormalChar] foo -# 46| [RegExpStar] (foo)* +# 59| [RegExpStar] (foo)* #-----| 0 -> [RegExpGroup] (foo) -# 46| [RegExpSequence] (foo)*bar +# 59| [RegExpSequence] (foo)*bar #-----| 0 -> [RegExpStar] (foo)* #-----| 1 -> [RegExpConstant, RegExpNormalChar] bar -# 46| [RegExpConstant, RegExpNormalChar] foo +# 59| [RegExpConstant, RegExpNormalChar] foo -# 46| [RegExpConstant, RegExpNormalChar] bar +# 59| [RegExpConstant, RegExpNormalChar] bar -# 47| [RegExpConstant, RegExpNormalChar] fo +# 60| [RegExpConstant, RegExpNormalChar] fo -# 47| [RegExpSequence] fo(o|b)ar +# 60| [RegExpSequence] fo(o|b)ar #-----| 0 -> [RegExpConstant, RegExpNormalChar] fo #-----| 1 -> [RegExpGroup] (o|b) #-----| 2 -> [RegExpConstant, RegExpNormalChar] ar -# 47| [RegExpGroup] (o|b) +# 60| [RegExpGroup] (o|b) #-----| 0 -> [RegExpAlt] o|b -# 47| [RegExpConstant, RegExpNormalChar] o +# 60| [RegExpConstant, RegExpNormalChar] o -# 47| [RegExpAlt] o|b +# 60| [RegExpAlt] o|b #-----| 0 -> [RegExpConstant, RegExpNormalChar] o #-----| 1 -> [RegExpConstant, RegExpNormalChar] b -# 47| [RegExpConstant, RegExpNormalChar] b +# 60| [RegExpConstant, RegExpNormalChar] b -# 47| [RegExpConstant, RegExpNormalChar] ar +# 60| [RegExpConstant, RegExpNormalChar] ar -# 48| [RegExpGroup] (a|b|cd) +# 61| [RegExpGroup] (a|b|cd) #-----| 0 -> [RegExpAlt] a|b|cd -# 48| [RegExpSequence] (a|b|cd)e +# 61| [RegExpSequence] (a|b|cd)e #-----| 0 -> [RegExpGroup] (a|b|cd) #-----| 1 -> [RegExpConstant, RegExpNormalChar] e -# 48| [RegExpConstant, RegExpNormalChar] a +# 61| [RegExpConstant, RegExpNormalChar] a -# 48| [RegExpAlt] a|b|cd +# 61| [RegExpAlt] a|b|cd #-----| 0 -> [RegExpConstant, RegExpNormalChar] a #-----| 1 -> [RegExpConstant, RegExpNormalChar] b #-----| 2 -> [RegExpConstant, RegExpNormalChar] cd -# 48| [RegExpConstant, RegExpNormalChar] b +# 61| [RegExpConstant, RegExpNormalChar] b -# 48| [RegExpConstant, RegExpNormalChar] cd +# 61| [RegExpConstant, RegExpNormalChar] cd -# 48| [RegExpConstant, RegExpNormalChar] e +# 61| [RegExpConstant, RegExpNormalChar] e -# 49| [RegExpGroup] (?::+) +# 62| [RegExpGroup] (?::+) #-----| 0 -> [RegExpPlus] :+ -# 49| [RegExpSequence] (?::+)\w +# 62| [RegExpSequence] (?::+)\w #-----| 0 -> [RegExpGroup] (?::+) #-----| 1 -> [RegExpCharacterClassEscape] \w -# 49| [RegExpConstant, RegExpNormalChar] : +# 62| [RegExpConstant, RegExpNormalChar] : -# 49| [RegExpPlus] :+ +# 62| [RegExpPlus] :+ #-----| 0 -> [RegExpConstant, RegExpNormalChar] : -# 49| [RegExpCharacterClassEscape] \w +# 62| [RegExpCharacterClassEscape] \w -# 52| [RegExpGroup] (?\w+) +# 65| [RegExpGroup] (?\w+) #-----| 0 -> [RegExpPlus] \w+ -# 52| [RegExpCharacterClassEscape] \w +# 65| [RegExpCharacterClassEscape] \w -# 52| [RegExpPlus] \w+ +# 65| [RegExpPlus] \w+ #-----| 0 -> [RegExpCharacterClassEscape] \w -# 53| [RegExpGroup] (?'foo'fo+) +# 66| [RegExpGroup] (?'foo'fo+) #-----| 0 -> [RegExpSequence] fo+ -# 53| [RegExpConstant, RegExpNormalChar] f +# 66| [RegExpConstant, RegExpNormalChar] f -# 53| [RegExpSequence] fo+ +# 66| [RegExpSequence] fo+ #-----| 0 -> [RegExpConstant, RegExpNormalChar] f #-----| 1 -> [RegExpPlus] o+ -# 53| [RegExpConstant, RegExpNormalChar] o +# 66| [RegExpConstant, RegExpNormalChar] o -# 53| [RegExpPlus] o+ +# 66| [RegExpPlus] o+ #-----| 0 -> [RegExpConstant, RegExpNormalChar] o -# 56| [RegExpGroup] (a+) +# 69| [RegExpGroup] (a+) #-----| 0 -> [RegExpPlus] a+ -# 56| [RegExpSequence] (a+)b+\1 +# 69| [RegExpSequence] (a+)b+\1 #-----| 0 -> [RegExpGroup] (a+) #-----| 1 -> [RegExpPlus] b+ #-----| 2 -> [RegExpBackRef] \1 -# 56| [RegExpConstant, RegExpNormalChar] a +# 69| [RegExpConstant, RegExpNormalChar] a -# 56| [RegExpPlus] a+ +# 69| [RegExpPlus] a+ #-----| 0 -> [RegExpConstant, RegExpNormalChar] a -# 56| [RegExpConstant, RegExpNormalChar] b +# 69| [RegExpConstant, RegExpNormalChar] b -# 56| [RegExpPlus] b+ +# 69| [RegExpPlus] b+ #-----| 0 -> [RegExpConstant, RegExpNormalChar] b -# 56| [RegExpBackRef] \1 +# 69| [RegExpBackRef] \1 -# 57| [RegExpGroup] (?q+) +# 70| [RegExpGroup] (?q+) #-----| 0 -> [RegExpPlus] q+ -# 57| [RegExpSequence] (?q+)\s+\k+ +# 70| [RegExpSequence] (?q+)\s+\k+ #-----| 0 -> [RegExpGroup] (?q+) #-----| 1 -> [RegExpPlus] \s+ #-----| 2 -> [RegExpPlus] \k+ -# 57| [RegExpConstant, RegExpNormalChar] q +# 70| [RegExpConstant, RegExpNormalChar] q -# 57| [RegExpPlus] q+ +# 70| [RegExpPlus] q+ #-----| 0 -> [RegExpConstant, RegExpNormalChar] q -# 57| [RegExpCharacterClassEscape] \s +# 70| [RegExpCharacterClassEscape] \s -# 57| [RegExpPlus] \s+ +# 70| [RegExpPlus] \s+ #-----| 0 -> [RegExpCharacterClassEscape] \s -# 57| [RegExpBackRef] \k +# 70| [RegExpBackRef] \k -# 57| [RegExpPlus] \k+ +# 70| [RegExpPlus] \k+ #-----| 0 -> [RegExpBackRef] \k -# 60| [RegExpNamedCharacterProperty] \p{Word} +# 73| [RegExpNamedCharacterProperty] \p{Word} -# 60| [RegExpStar] \p{Word}* +# 73| [RegExpStar] \p{Word}* #-----| 0 -> [RegExpNamedCharacterProperty] \p{Word} -# 61| [RegExpNamedCharacterProperty] \P{Digit} +# 74| [RegExpNamedCharacterProperty] \P{Digit} -# 61| [RegExpPlus] \P{Digit}+ +# 74| [RegExpPlus] \P{Digit}+ #-----| 0 -> [RegExpNamedCharacterProperty] \P{Digit} -# 62| [RegExpNamedCharacterProperty] \p{^Alnum} +# 75| [RegExpNamedCharacterProperty] \p{^Alnum} -# 62| [RegExpRange] \p{^Alnum}{2,3} +# 75| [RegExpRange] \p{^Alnum}{2,3} #-----| 0 -> [RegExpNamedCharacterProperty] \p{^Alnum} -# 63| [RegExpCharacterClass] [a-f\p{Digit}] +# 76| [RegExpCharacterClass] [a-f\p{Digit}] #-----| 0 -> [RegExpCharacterRange] a-f #-----| 1 -> [RegExpNamedCharacterProperty] \p{Digit} -# 63| [RegExpPlus] [a-f\p{Digit}]+ +# 76| [RegExpPlus] [a-f\p{Digit}]+ #-----| 0 -> [RegExpCharacterClass] [a-f\p{Digit}] -# 63| [RegExpConstant, RegExpNormalChar] a +# 76| [RegExpConstant, RegExpNormalChar] a -# 63| [RegExpCharacterRange] a-f +# 76| [RegExpCharacterRange] a-f #-----| 0 -> [RegExpConstant, RegExpNormalChar] a #-----| 1 -> [RegExpConstant, RegExpNormalChar] f -# 63| [RegExpConstant, RegExpNormalChar] f +# 76| [RegExpConstant, RegExpNormalChar] f -# 63| [RegExpNamedCharacterProperty] \p{Digit} +# 76| [RegExpNamedCharacterProperty] \p{Digit} -# 66| [RegExpCharacterClass] [[:alpha:]] +# 79| [RegExpCharacterClass] [[:alpha:]] #-----| 0 -> [RegExpNamedCharacterProperty] [:alpha:] -# 66| [RegExpSequence] [[:alpha:]][[:digit:]] +# 79| [RegExpSequence] [[:alpha:]][[:digit:]] #-----| 0 -> [RegExpCharacterClass] [[:alpha:]] #-----| 1 -> [RegExpCharacterClass] [[:digit:]] -# 66| [RegExpNamedCharacterProperty] [:alpha:] +# 79| [RegExpNamedCharacterProperty] [:alpha:] -# 66| [RegExpCharacterClass] [[:digit:]] +# 79| [RegExpCharacterClass] [[:digit:]] #-----| 0 -> [RegExpNamedCharacterProperty] [:digit:] -# 66| [RegExpNamedCharacterProperty] [:digit:] +# 79| [RegExpNamedCharacterProperty] [:digit:] -# 69| [RegExpCharacterClass] [[:alpha:][:digit:]] +# 82| [RegExpCharacterClass] [[:alpha:][:digit:]] #-----| 0 -> [RegExpNamedCharacterProperty] [:alpha:] #-----| 1 -> [RegExpNamedCharacterProperty] [:digit:] -# 69| [RegExpNamedCharacterProperty] [:alpha:] +# 82| [RegExpNamedCharacterProperty] [:alpha:] -# 69| [RegExpNamedCharacterProperty] [:digit:] +# 82| [RegExpNamedCharacterProperty] [:digit:] -# 72| [RegExpCharacterClass] [A-F[:digit:]a-f] +# 85| [RegExpCharacterClass] [A-F[:digit:]a-f] #-----| 0 -> [RegExpCharacterRange] A-F #-----| 1 -> [RegExpNamedCharacterProperty] [:digit:] #-----| 2 -> [RegExpCharacterRange] a-f -# 72| [RegExpConstant, RegExpNormalChar] A +# 85| [RegExpConstant, RegExpNormalChar] A -# 72| [RegExpCharacterRange] A-F +# 85| [RegExpCharacterRange] A-F #-----| 0 -> [RegExpConstant, RegExpNormalChar] A #-----| 1 -> [RegExpConstant, RegExpNormalChar] F -# 72| [RegExpConstant, RegExpNormalChar] F +# 85| [RegExpConstant, RegExpNormalChar] F -# 72| [RegExpNamedCharacterProperty] [:digit:] +# 85| [RegExpNamedCharacterProperty] [:digit:] -# 72| [RegExpConstant, RegExpNormalChar] a +# 85| [RegExpConstant, RegExpNormalChar] a -# 72| [RegExpCharacterRange] a-f +# 85| [RegExpCharacterRange] a-f #-----| 0 -> [RegExpConstant, RegExpNormalChar] a #-----| 1 -> [RegExpConstant, RegExpNormalChar] f -# 72| [RegExpConstant, RegExpNormalChar] f +# 85| [RegExpConstant, RegExpNormalChar] f -# 75| [RegExpNamedCharacterProperty] [:digit:] +# 88| [RegExpNamedCharacterProperty] [:digit:] -# 79| [RegExpConstant, RegExpNormalChar] abc - -# 82| [RegExpConstant, RegExpEscape] \u{987 +# 91| [RegExpConstant, RegExpEscape] \u{987 diff --git a/cpp/ql/test/library-tests/regex/parse.ql b/cpp/ql/test/library-tests/regex/parse.ql index ba9a04ab9bd7..2e9debf3784a 100644 --- a/cpp/ql/test/library-tests/regex/parse.ql +++ b/cpp/ql/test/library-tests/regex/parse.ql @@ -2,8 +2,14 @@ * @kind graph */ +import semmle.code.cpp.regex.internal.ParseRegExp import semmle.code.cpp.regex.RegexTreeView +// Stop gap for missing flow configs +class RegExpTest extends RegExp { + RegExpTest() { any() } +} + query predicate nodes(RegExpTerm n, string attr, string val) { attr = "semmle.label" and val = "[" + concat(n.getAPrimaryQlClass(), ", ") + "] " + n.toString() diff --git a/cpp/ql/test/library-tests/regex/regexp.cpp b/cpp/ql/test/library-tests/regex/regexp.cpp index a68c4878094f..d0ba8099db5a 100644 --- a/cpp/ql/test/library-tests/regex/regexp.cpp +++ b/cpp/ql/test/library-tests/regex/regexp.cpp @@ -1,82 +1,91 @@ -# Empty -// - -# Basic sequence -/abc/ - -# Repetition -/a*b+c?d/ -/a{4,8}/ -/a{,8}/ -/a{3,}/ -/a{7}/ - -# Alternation -/foo|bar/ - -# Character classes -/[abc]/ -/[a-fA-F0-9_]/ -/\A[+-]?\d+/ -/[\w]+/ -/\[\][123]/ -/[^A-Z]/ -/[]]/ # MRI gives a warning, but accepts this as matching ']' -/[^]]/ # MRI gives a warning, but accepts this as matching anything except ']' -/[^-]/ -/[|]/ - -# Nested character classes -/[[a-f]A-F]/ # BAD - not parsed correctly - -# Meta-character classes -/.*/ -/.*/m -/\w+\W/ -/\s\S/ -/\d\D/ -/\h\H/ -/\n\r\t/ - -# Anchors -/\Gabc/ -/\b!a\B/ - -# Groups -/(foo)*bar/ -/fo(o|b)ar/ -/(a|b|cd)e/ -/(?::+)\w/ # Non-capturing group matching colons - -# Named groups -/(?\w+)/ -/(?'foo'fo+)/ - -# Backreferences -/(a+)b+\1/ -/(?q+)\s+\k+/ - -# Named character properties using the p-style syntax -/\p{Word}*/ -/\P{Digit}+/ -/\p{^Alnum}{2,3}/ -/[a-f\p{Digit}]+/ # Also valid inside character classes - -# Two separate character classes, each containing a single POSIX bracket expression -/[[:alpha:]][[:digit:]]/ - -# A single character class containing two POSIX bracket expressions -/[[:alpha:][:digit:]]/ - -# A single character class containing two ranges and one POSIX bracket expression -/[A-F[:digit:]a-f]/ - -# *Not* a POSIX bracket expression; just a regular character class. -/[:digit:]/ - -# Simple constant interpolation -A = "a" -/#{A}bc/ - -# unicode -/\u{9879}/ \ No newline at end of file +// semmle-extractor-options: -std=c++17 + +namespace std { + template + class basic_regex { + public: + basic_regex(const char *s) {} + basic_regex(const char *s, int flags) {} + basic_regex &assign(const char *s) { return *this; } + }; + typedef basic_regex regex; +} // namespace std + +// Empty +std::regex r_empty(""); + +// Basic sequence +std::regex r_abc("abc"); + +// Repetition +std::regex r_rep1("a*b+c?d"); +std::regex r_rep2("a{4,8}"); +std::regex r_rep3("a{,8}"); +std::regex r_rep4("a{3,}"); +std::regex r_rep5("a{7}"); + +// Alternation +std::regex r_alt("foo|bar"); + +// Character classes +std::regex r_cc1("[abc]"); +std::regex r_cc2("[a-fA-F0-9_]"); +std::regex r_cc3("\\A[+-]?\\d+"); +std::regex r_cc4("[\\w]+"); +std::regex r_cc5("\\[\\][123]"); +std::regex r_cc6("[^A-Z]"); +std::regex r_cc7("[]]"); // MRI gives a warning, but accepts this as matching ']' +std::regex r_cc8("[^]]"); // MRI gives a warning, but accepts this as matching anything except ']' +std::regex r_cc9("[^-]"); +std::regex r_cc10("[|]"); + +// Nested character classes (BAD - not parsed correctly) +std::regex r_nested("[[a-f]A-F]"); + +// Meta-character classes +std::regex r_meta1(".*"); +std::regex r_meta1m(".*"); // /.*/m mode variant — mode flags are constructor args in C++ +std::regex r_meta2("\\w+\\W"); +std::regex r_meta3("\\s\\S"); +std::regex r_meta4("\\d\\D"); +std::regex r_meta5("\\h\\H"); +std::regex r_meta6("\\n\\r\\t"); + +// Anchors +std::regex r_anc1("\\Gabc"); +std::regex r_anc2("\\b!a\\B"); + +// Groups +std::regex r_grp1("(foo)*bar"); +std::regex r_grp2("fo(o|b)ar"); +std::regex r_grp3("(a|b|cd)e"); +std::regex r_grp4("(?::+)\\w"); // Non-capturing group matching colons + +// Named groups +std::regex r_ng1("(?\\w+)"); +std::regex r_ng2("(?'foo'fo+)"); // single-quote named-group form + +// Backreferences +std::regex r_bref1("(a+)b+\\1"); +std::regex r_bref2("(?q+)\\s+\\k+"); + +// Named character properties using the p-style syntax +std::regex r_prop1("\\p{Word}*"); +std::regex r_prop2("\\P{Digit}+"); +std::regex r_prop3("\\p{^Alnum}{2,3}"); +std::regex r_prop4("[a-f\\p{Digit}]+"); // Also valid inside character classes + +// Two separate character classes, each containing a single POSIX bracket expression +std::regex r_posix1("[[:alpha:]][[:digit:]]"); + +// A single character class containing two POSIX bracket expressions +std::regex r_posix2("[[:alpha:][:digit:]]"); + +// A single character class containing two ranges and one POSIX bracket expression +std::regex r_posix3("[A-F[:digit:]a-f]"); + +// *Not* a POSIX bracket expression; just a regular character class. +std::regex r_posix4("[:digit:]"); + +// unicode +std::regex r_uni("\\u{9879}"); diff --git a/cpp/ql/test/library-tests/regex/regexp.expected b/cpp/ql/test/library-tests/regex/regexp.expected index e464b5ce5ea5..6b2409e7c7c0 100644 --- a/cpp/ql/test/library-tests/regex/regexp.expected +++ b/cpp/ql/test/library-tests/regex/regexp.expected @@ -1,270 +1,268 @@ groupName -| regexp.rb:52:2:52:11 | (?\\w+) | id | -| regexp.rb:53:2:53:12 | (?'foo'fo+) | foo | -| regexp.rb:57:2:57:11 | (?q+) | qux | +| regexp.cpp:65:19:65:28 | (?\\w+) | id | +| regexp.cpp:66:19:66:29 | (?'foo'fo+) | foo | +| regexp.cpp:70:21:70:30 | (?q+) | qux | groupNumber -| regexp.rb:46:2:46:6 | (foo) | 1 | -| regexp.rb:47:4:47:8 | (o\|b) | 1 | -| regexp.rb:48:2:48:9 | (a\|b\|cd) | 1 | -| regexp.rb:53:2:53:12 | (?'foo'fo+) | 1 | -| regexp.rb:56:2:56:5 | (a+) | 1 | +| regexp.cpp:59:20:59:24 | (foo) | 1 | +| regexp.cpp:60:22:60:26 | (o\|b) | 1 | +| regexp.cpp:61:20:61:27 | (a\|b\|cd) | 1 | +| regexp.cpp:66:19:66:29 | (?'foo'fo+) | 1 | +| regexp.cpp:69:21:69:24 | (a+) | 1 | term -| regexp.rb:5:2:5:4 | abc | RegExpConstant,RegExpNormalChar | -| regexp.rb:8:2:8:2 | a | RegExpConstant,RegExpNormalChar | -| regexp.rb:8:2:8:3 | a* | RegExpStar | -| regexp.rb:8:2:8:8 | a*b+c?d | RegExpSequence | -| regexp.rb:8:4:8:4 | b | RegExpConstant,RegExpNormalChar | -| regexp.rb:8:4:8:5 | b+ | RegExpPlus | -| regexp.rb:8:6:8:6 | c | RegExpConstant,RegExpNormalChar | -| regexp.rb:8:6:8:7 | c? | RegExpOpt | -| regexp.rb:8:8:8:8 | d | RegExpConstant,RegExpNormalChar | -| regexp.rb:9:2:9:2 | a | RegExpConstant,RegExpNormalChar | -| regexp.rb:9:2:9:7 | a{4,8} | RegExpRange | -| regexp.rb:10:2:10:2 | a | RegExpConstant,RegExpNormalChar | -| regexp.rb:10:2:10:6 | a{,8} | RegExpRange | -| regexp.rb:11:2:11:2 | a | RegExpConstant,RegExpNormalChar | -| regexp.rb:11:2:11:6 | a{3,} | InfiniteRepetitionQuantifier,RegExpRange | -| regexp.rb:12:2:12:2 | a | RegExpConstant,RegExpNormalChar | -| regexp.rb:12:2:12:5 | a{7} | RegExpRange | -| regexp.rb:15:2:15:4 | foo | RegExpConstant,RegExpNormalChar | -| regexp.rb:15:2:15:8 | foo\|bar | RegExpAlt | -| regexp.rb:15:6:15:8 | bar | RegExpConstant,RegExpNormalChar | -| regexp.rb:18:2:18:6 | [abc] | RegExpCharacterClass | -| regexp.rb:18:3:18:3 | a | RegExpConstant,RegExpNormalChar | -| regexp.rb:18:4:18:4 | b | RegExpConstant,RegExpNormalChar | -| regexp.rb:18:5:18:5 | c | RegExpConstant,RegExpNormalChar | -| regexp.rb:19:2:19:13 | [a-fA-F0-9_] | RegExpCharacterClass | -| regexp.rb:19:3:19:3 | a | RegExpConstant,RegExpNormalChar | -| regexp.rb:19:3:19:5 | a-f | RegExpCharacterRange | -| regexp.rb:19:5:19:5 | f | RegExpConstant,RegExpNormalChar | -| regexp.rb:19:6:19:6 | A | RegExpConstant,RegExpNormalChar | -| regexp.rb:19:6:19:8 | A-F | RegExpCharacterRange | -| regexp.rb:19:8:19:8 | F | RegExpConstant,RegExpNormalChar | -| regexp.rb:19:9:19:9 | 0 | RegExpConstant,RegExpNormalChar | -| regexp.rb:19:9:19:11 | 0-9 | RegExpCharacterRange | -| regexp.rb:19:11:19:11 | 9 | RegExpConstant,RegExpNormalChar | -| regexp.rb:19:12:19:12 | _ | RegExpConstant,RegExpNormalChar | -| regexp.rb:20:2:20:3 | \\A | RegExpCaret | -| regexp.rb:20:2:20:11 | \\A[+-]?\\d+ | RegExpSequence | -| regexp.rb:20:4:20:7 | [+-] | RegExpCharacterClass | -| regexp.rb:20:4:20:8 | [+-]? | RegExpOpt | -| regexp.rb:20:5:20:5 | + | RegExpConstant,RegExpNormalChar | -| regexp.rb:20:6:20:6 | - | RegExpConstant,RegExpNormalChar | -| regexp.rb:20:9:20:10 | \\d | RegExpCharacterClassEscape | -| regexp.rb:20:9:20:11 | \\d+ | RegExpPlus | -| regexp.rb:21:2:21:5 | [\\w] | RegExpCharacterClass | -| regexp.rb:21:2:21:6 | [\\w]+ | RegExpPlus | -| regexp.rb:21:3:21:4 | \\w | RegExpCharacterClassEscape | -| regexp.rb:22:2:22:3 | \\[ | RegExpConstant,RegExpEscape | -| regexp.rb:22:2:22:10 | \\[\\][123] | RegExpSequence | -| regexp.rb:22:4:22:5 | \\] | RegExpConstant,RegExpEscape | -| regexp.rb:22:6:22:10 | [123] | RegExpCharacterClass | -| regexp.rb:22:7:22:7 | 1 | RegExpConstant,RegExpNormalChar | -| regexp.rb:22:8:22:8 | 2 | RegExpConstant,RegExpNormalChar | -| regexp.rb:22:9:22:9 | 3 | RegExpConstant,RegExpNormalChar | -| regexp.rb:23:2:23:7 | [^A-Z] | RegExpCharacterClass | -| regexp.rb:23:4:23:4 | A | RegExpConstant,RegExpNormalChar | -| regexp.rb:23:4:23:6 | A-Z | RegExpCharacterRange | -| regexp.rb:23:6:23:6 | Z | RegExpConstant,RegExpNormalChar | -| regexp.rb:24:2:24:4 | []] | RegExpCharacterClass | -| regexp.rb:24:3:24:3 | ] | RegExpConstant,RegExpNormalChar | -| regexp.rb:25:2:25:5 | [^]] | RegExpCharacterClass | -| regexp.rb:25:4:25:4 | ] | RegExpConstant,RegExpNormalChar | -| regexp.rb:26:2:26:5 | [^-] | RegExpCharacterClass | -| regexp.rb:26:4:26:4 | - | RegExpConstant,RegExpNormalChar | -| regexp.rb:27:2:27:4 | [\|] | RegExpCharacterClass | -| regexp.rb:27:3:27:3 | \| | RegExpConstant,RegExpNormalChar | -| regexp.rb:30:2:30:7 | [[a-f] | RegExpCharacterClass | -| regexp.rb:30:2:30:11 | [[a-f]A-F] | RegExpSequence | -| regexp.rb:30:3:30:3 | [ | RegExpConstant,RegExpNormalChar | -| regexp.rb:30:4:30:4 | a | RegExpConstant,RegExpNormalChar | -| regexp.rb:30:4:30:6 | a-f | RegExpCharacterRange | -| regexp.rb:30:6:30:6 | f | RegExpConstant,RegExpNormalChar | -| regexp.rb:30:8:30:11 | A-F] | RegExpConstant,RegExpNormalChar | -| regexp.rb:33:2:33:2 | . | RegExpDot | -| regexp.rb:33:2:33:3 | .* | RegExpStar | -| regexp.rb:34:2:34:2 | . | RegExpDot | -| regexp.rb:34:2:34:3 | .* | RegExpStar | -| regexp.rb:35:2:35:3 | \\w | RegExpCharacterClassEscape | -| regexp.rb:35:2:35:4 | \\w+ | RegExpPlus | -| regexp.rb:35:2:35:6 | \\w+\\W | RegExpSequence | -| regexp.rb:35:5:35:6 | \\W | RegExpCharacterClassEscape | -| regexp.rb:36:2:36:3 | \\s | RegExpCharacterClassEscape | -| regexp.rb:36:2:36:5 | \\s\\S | RegExpSequence | -| regexp.rb:36:4:36:5 | \\S | RegExpCharacterClassEscape | -| regexp.rb:37:2:37:3 | \\d | RegExpCharacterClassEscape | -| regexp.rb:37:2:37:5 | \\d\\D | RegExpSequence | -| regexp.rb:37:4:37:5 | \\D | RegExpCharacterClassEscape | -| regexp.rb:38:2:38:3 | \\h | RegExpCharacterClassEscape | -| regexp.rb:38:2:38:5 | \\h\\H | RegExpSequence | -| regexp.rb:38:4:38:5 | \\H | RegExpCharacterClassEscape | -| regexp.rb:39:2:39:3 | \\n | RegExpConstant,RegExpEscape | -| regexp.rb:39:2:39:7 | \\n\\r\\t | RegExpSequence | -| regexp.rb:39:4:39:5 | \\r | RegExpConstant,RegExpEscape | -| regexp.rb:39:6:39:7 | \\t | RegExpConstant,RegExpEscape | -| regexp.rb:42:2:42:3 | \\G | RegExpSpecialChar | -| regexp.rb:42:2:42:6 | \\Gabc | RegExpSequence | -| regexp.rb:42:4:42:6 | abc | RegExpConstant,RegExpNormalChar | -| regexp.rb:43:2:43:3 | \\b | RegExpSpecialChar | -| regexp.rb:43:2:43:7 | \\b!a\\B | RegExpSequence | -| regexp.rb:43:4:43:5 | !a | RegExpConstant,RegExpNormalChar | -| regexp.rb:43:6:43:7 | \\B | RegExpNonWordBoundary | -| regexp.rb:46:2:46:6 | (foo) | RegExpGroup | -| regexp.rb:46:2:46:7 | (foo)* | RegExpStar | -| regexp.rb:46:2:46:10 | (foo)*bar | RegExpSequence | -| regexp.rb:46:3:46:5 | foo | RegExpConstant,RegExpNormalChar | -| regexp.rb:46:8:46:10 | bar | RegExpConstant,RegExpNormalChar | -| regexp.rb:47:2:47:3 | fo | RegExpConstant,RegExpNormalChar | -| regexp.rb:47:2:47:10 | fo(o\|b)ar | RegExpSequence | -| regexp.rb:47:4:47:8 | (o\|b) | RegExpGroup | -| regexp.rb:47:5:47:5 | o | RegExpConstant,RegExpNormalChar | -| regexp.rb:47:5:47:7 | o\|b | RegExpAlt | -| regexp.rb:47:7:47:7 | b | RegExpConstant,RegExpNormalChar | -| regexp.rb:47:9:47:10 | ar | RegExpConstant,RegExpNormalChar | -| regexp.rb:48:2:48:9 | (a\|b\|cd) | RegExpGroup | -| regexp.rb:48:2:48:10 | (a\|b\|cd)e | RegExpSequence | -| regexp.rb:48:3:48:3 | a | RegExpConstant,RegExpNormalChar | -| regexp.rb:48:3:48:8 | a\|b\|cd | RegExpAlt | -| regexp.rb:48:5:48:5 | b | RegExpConstant,RegExpNormalChar | -| regexp.rb:48:7:48:8 | cd | RegExpConstant,RegExpNormalChar | -| regexp.rb:48:10:48:10 | e | RegExpConstant,RegExpNormalChar | -| regexp.rb:49:2:49:7 | (?::+) | RegExpGroup | -| regexp.rb:49:2:49:9 | (?::+)\\w | RegExpSequence | -| regexp.rb:49:5:49:5 | : | RegExpConstant,RegExpNormalChar | -| regexp.rb:49:5:49:6 | :+ | RegExpPlus | -| regexp.rb:49:8:49:9 | \\w | RegExpCharacterClassEscape | -| regexp.rb:52:2:52:11 | (?\\w+) | RegExpGroup | -| regexp.rb:52:8:52:9 | \\w | RegExpCharacterClassEscape | -| regexp.rb:52:8:52:10 | \\w+ | RegExpPlus | -| regexp.rb:53:2:53:12 | (?'foo'fo+) | RegExpGroup | -| regexp.rb:53:9:53:9 | f | RegExpConstant,RegExpNormalChar | -| regexp.rb:53:9:53:11 | fo+ | RegExpSequence | -| regexp.rb:53:10:53:10 | o | RegExpConstant,RegExpNormalChar | -| regexp.rb:53:10:53:11 | o+ | RegExpPlus | -| regexp.rb:56:2:56:5 | (a+) | RegExpGroup | -| regexp.rb:56:2:56:9 | (a+)b+\\1 | RegExpSequence | -| regexp.rb:56:3:56:3 | a | RegExpConstant,RegExpNormalChar | -| regexp.rb:56:3:56:4 | a+ | RegExpPlus | -| regexp.rb:56:6:56:6 | b | RegExpConstant,RegExpNormalChar | -| regexp.rb:56:6:56:7 | b+ | RegExpPlus | -| regexp.rb:56:8:56:9 | \\1 | RegExpBackRef | -| regexp.rb:57:2:57:11 | (?q+) | RegExpGroup | -| regexp.rb:57:2:57:22 | (?q+)\\s+\\k+ | RegExpSequence | -| regexp.rb:57:9:57:9 | q | RegExpConstant,RegExpNormalChar | -| regexp.rb:57:9:57:10 | q+ | RegExpPlus | -| regexp.rb:57:12:57:13 | \\s | RegExpCharacterClassEscape | -| regexp.rb:57:12:57:14 | \\s+ | RegExpPlus | -| regexp.rb:57:15:57:21 | \\k | RegExpBackRef | -| regexp.rb:57:15:57:22 | \\k+ | RegExpPlus | -| regexp.rb:60:2:60:9 | \\p{Word} | RegExpNamedCharacterProperty | -| regexp.rb:60:2:60:10 | \\p{Word}* | RegExpStar | -| regexp.rb:61:2:61:10 | \\P{Digit} | RegExpNamedCharacterProperty | -| regexp.rb:61:2:61:11 | \\P{Digit}+ | RegExpPlus | -| regexp.rb:62:2:62:11 | \\p{^Alnum} | RegExpNamedCharacterProperty | -| regexp.rb:62:2:62:16 | \\p{^Alnum}{2,3} | RegExpRange | -| regexp.rb:63:2:63:15 | [a-f\\p{Digit}] | RegExpCharacterClass | -| regexp.rb:63:2:63:16 | [a-f\\p{Digit}]+ | RegExpPlus | -| regexp.rb:63:3:63:3 | a | RegExpConstant,RegExpNormalChar | -| regexp.rb:63:3:63:5 | a-f | RegExpCharacterRange | -| regexp.rb:63:5:63:5 | f | RegExpConstant,RegExpNormalChar | -| regexp.rb:63:6:63:14 | \\p{Digit} | RegExpNamedCharacterProperty | -| regexp.rb:66:2:66:12 | [[:alpha:]] | RegExpCharacterClass | -| regexp.rb:66:2:66:23 | [[:alpha:]][[:digit:]] | RegExpSequence | -| regexp.rb:66:3:66:11 | [:alpha:] | RegExpNamedCharacterProperty | -| regexp.rb:66:13:66:23 | [[:digit:]] | RegExpCharacterClass | -| regexp.rb:66:14:66:22 | [:digit:] | RegExpNamedCharacterProperty | -| regexp.rb:69:2:69:21 | [[:alpha:][:digit:]] | RegExpCharacterClass | -| regexp.rb:69:3:69:11 | [:alpha:] | RegExpNamedCharacterProperty | -| regexp.rb:69:12:69:20 | [:digit:] | RegExpNamedCharacterProperty | -| regexp.rb:72:2:72:18 | [A-F[:digit:]a-f] | RegExpCharacterClass | -| regexp.rb:72:3:72:3 | A | RegExpConstant,RegExpNormalChar | -| regexp.rb:72:3:72:5 | A-F | RegExpCharacterRange | -| regexp.rb:72:5:72:5 | F | RegExpConstant,RegExpNormalChar | -| regexp.rb:72:6:72:14 | [:digit:] | RegExpNamedCharacterProperty | -| regexp.rb:72:15:72:15 | a | RegExpConstant,RegExpNormalChar | -| regexp.rb:72:15:72:17 | a-f | RegExpCharacterRange | -| regexp.rb:72:17:72:17 | f | RegExpConstant,RegExpNormalChar | -| regexp.rb:75:2:75:10 | [:digit:] | RegExpNamedCharacterProperty | -| regexp.rb:79:2:79:4 | abc | RegExpConstant,RegExpNormalChar | -| regexp.rb:82:2:82:7 | \\u{987 | RegExpConstant,RegExpEscape | +| regexp.cpp:18:19:18:21 | abc | RegExpConstant,RegExpNormalChar | +| regexp.cpp:21:20:21:20 | a | RegExpConstant,RegExpNormalChar | +| regexp.cpp:21:20:21:21 | a* | RegExpStar | +| regexp.cpp:21:20:21:26 | a*b+c?d | RegExpSequence | +| regexp.cpp:21:22:21:22 | b | RegExpConstant,RegExpNormalChar | +| regexp.cpp:21:22:21:23 | b+ | RegExpPlus | +| regexp.cpp:21:24:21:24 | c | RegExpConstant,RegExpNormalChar | +| regexp.cpp:21:24:21:25 | c? | RegExpOpt | +| regexp.cpp:21:26:21:26 | d | RegExpConstant,RegExpNormalChar | +| regexp.cpp:22:20:22:20 | a | RegExpConstant,RegExpNormalChar | +| regexp.cpp:22:20:22:25 | a{4,8} | RegExpRange | +| regexp.cpp:23:20:23:20 | a | RegExpConstant,RegExpNormalChar | +| regexp.cpp:23:20:23:24 | a{,8} | RegExpRange | +| regexp.cpp:24:20:24:20 | a | RegExpConstant,RegExpNormalChar | +| regexp.cpp:24:20:24:24 | a{3,} | InfiniteRepetitionQuantifier,RegExpRange | +| regexp.cpp:25:20:25:20 | a | RegExpConstant,RegExpNormalChar | +| regexp.cpp:25:20:25:23 | a{7} | RegExpRange | +| regexp.cpp:28:19:28:21 | foo | RegExpConstant,RegExpNormalChar | +| regexp.cpp:28:19:28:25 | foo\|bar | RegExpAlt | +| regexp.cpp:28:23:28:25 | bar | RegExpConstant,RegExpNormalChar | +| regexp.cpp:31:19:31:23 | [abc] | RegExpCharacterClass | +| regexp.cpp:31:20:31:20 | a | RegExpConstant,RegExpNormalChar | +| regexp.cpp:31:21:31:21 | b | RegExpConstant,RegExpNormalChar | +| regexp.cpp:31:22:31:22 | c | RegExpConstant,RegExpNormalChar | +| regexp.cpp:32:19:32:30 | [a-fA-F0-9_] | RegExpCharacterClass | +| regexp.cpp:32:20:32:20 | a | RegExpConstant,RegExpNormalChar | +| regexp.cpp:32:20:32:22 | a-f | RegExpCharacterRange | +| regexp.cpp:32:22:32:22 | f | RegExpConstant,RegExpNormalChar | +| regexp.cpp:32:23:32:23 | A | RegExpConstant,RegExpNormalChar | +| regexp.cpp:32:23:32:25 | A-F | RegExpCharacterRange | +| regexp.cpp:32:25:32:25 | F | RegExpConstant,RegExpNormalChar | +| regexp.cpp:32:26:32:26 | 0 | RegExpConstant,RegExpNormalChar | +| regexp.cpp:32:26:32:28 | 0-9 | RegExpCharacterRange | +| regexp.cpp:32:28:32:28 | 9 | RegExpConstant,RegExpNormalChar | +| regexp.cpp:32:29:32:29 | _ | RegExpConstant,RegExpNormalChar | +| regexp.cpp:33:19:33:20 | \\A | RegExpCaret | +| regexp.cpp:33:19:33:28 | \\A[+-]?\\d+ | RegExpSequence | +| regexp.cpp:33:21:33:24 | [+-] | RegExpCharacterClass | +| regexp.cpp:33:21:33:25 | [+-]? | RegExpOpt | +| regexp.cpp:33:22:33:22 | + | RegExpConstant,RegExpNormalChar | +| regexp.cpp:33:23:33:23 | - | RegExpConstant,RegExpNormalChar | +| regexp.cpp:33:26:33:27 | \\d | RegExpCharacterClassEscape | +| regexp.cpp:33:26:33:28 | \\d+ | RegExpPlus | +| regexp.cpp:34:19:34:22 | [\\w] | RegExpCharacterClass | +| regexp.cpp:34:19:34:23 | [\\w]+ | RegExpPlus | +| regexp.cpp:34:20:34:21 | \\w | RegExpCharacterClassEscape | +| regexp.cpp:35:19:35:20 | \\[ | RegExpConstant,RegExpEscape | +| regexp.cpp:35:19:35:27 | \\[\\][123] | RegExpSequence | +| regexp.cpp:35:21:35:22 | \\] | RegExpConstant,RegExpEscape | +| regexp.cpp:35:23:35:27 | [123] | RegExpCharacterClass | +| regexp.cpp:35:24:35:24 | 1 | RegExpConstant,RegExpNormalChar | +| regexp.cpp:35:25:35:25 | 2 | RegExpConstant,RegExpNormalChar | +| regexp.cpp:35:26:35:26 | 3 | RegExpConstant,RegExpNormalChar | +| regexp.cpp:36:19:36:24 | [^A-Z] | RegExpCharacterClass | +| regexp.cpp:36:21:36:21 | A | RegExpConstant,RegExpNormalChar | +| regexp.cpp:36:21:36:23 | A-Z | RegExpCharacterRange | +| regexp.cpp:36:23:36:23 | Z | RegExpConstant,RegExpNormalChar | +| regexp.cpp:37:19:37:21 | []] | RegExpCharacterClass | +| regexp.cpp:37:20:37:20 | ] | RegExpConstant,RegExpNormalChar | +| regexp.cpp:38:19:38:22 | [^]] | RegExpCharacterClass | +| regexp.cpp:38:21:38:21 | ] | RegExpConstant,RegExpNormalChar | +| regexp.cpp:39:19:39:22 | [^-] | RegExpCharacterClass | +| regexp.cpp:39:21:39:21 | - | RegExpConstant,RegExpNormalChar | +| regexp.cpp:40:20:40:22 | [\|] | RegExpCharacterClass | +| regexp.cpp:40:21:40:21 | \| | RegExpConstant,RegExpNormalChar | +| regexp.cpp:43:22:43:27 | [[a-f] | RegExpCharacterClass | +| regexp.cpp:43:22:43:31 | [[a-f]A-F] | RegExpSequence | +| regexp.cpp:43:23:43:23 | [ | RegExpConstant,RegExpNormalChar | +| regexp.cpp:43:24:43:24 | a | RegExpConstant,RegExpNormalChar | +| regexp.cpp:43:24:43:26 | a-f | RegExpCharacterRange | +| regexp.cpp:43:26:43:26 | f | RegExpConstant,RegExpNormalChar | +| regexp.cpp:43:28:43:31 | A-F] | RegExpConstant,RegExpNormalChar | +| regexp.cpp:46:21:46:21 | . | RegExpDot | +| regexp.cpp:46:21:46:22 | .* | RegExpStar | +| regexp.cpp:47:22:47:22 | . | RegExpDot | +| regexp.cpp:47:22:47:23 | .* | RegExpStar | +| regexp.cpp:48:21:48:22 | \\w | RegExpCharacterClassEscape | +| regexp.cpp:48:21:48:23 | \\w+ | RegExpPlus | +| regexp.cpp:48:21:48:25 | \\w+\\W | RegExpSequence | +| regexp.cpp:48:24:48:25 | \\W | RegExpCharacterClassEscape | +| regexp.cpp:49:21:49:22 | \\s | RegExpCharacterClassEscape | +| regexp.cpp:49:21:49:24 | \\s\\S | RegExpSequence | +| regexp.cpp:49:23:49:24 | \\S | RegExpCharacterClassEscape | +| regexp.cpp:50:21:50:22 | \\d | RegExpCharacterClassEscape | +| regexp.cpp:50:21:50:24 | \\d\\D | RegExpSequence | +| regexp.cpp:50:23:50:24 | \\D | RegExpCharacterClassEscape | +| regexp.cpp:51:21:51:22 | \\h | RegExpCharacterClassEscape | +| regexp.cpp:51:21:51:24 | \\h\\H | RegExpSequence | +| regexp.cpp:51:23:51:24 | \\H | RegExpCharacterClassEscape | +| regexp.cpp:52:21:52:22 | \\n | RegExpConstant,RegExpEscape | +| regexp.cpp:52:21:52:26 | \\n\\r\\t | RegExpSequence | +| regexp.cpp:52:23:52:24 | \\r | RegExpConstant,RegExpEscape | +| regexp.cpp:52:25:52:26 | \\t | RegExpConstant,RegExpEscape | +| regexp.cpp:55:20:55:21 | \\G | RegExpSpecialChar | +| regexp.cpp:55:20:55:24 | \\Gabc | RegExpSequence | +| regexp.cpp:55:22:55:24 | abc | RegExpConstant,RegExpNormalChar | +| regexp.cpp:56:20:56:21 | \\b | RegExpSpecialChar | +| regexp.cpp:56:20:56:25 | \\b!a\\B | RegExpSequence | +| regexp.cpp:56:22:56:23 | !a | RegExpConstant,RegExpNormalChar | +| regexp.cpp:56:24:56:25 | \\B | RegExpNonWordBoundary | +| regexp.cpp:59:20:59:24 | (foo) | RegExpGroup | +| regexp.cpp:59:20:59:25 | (foo)* | RegExpStar | +| regexp.cpp:59:20:59:28 | (foo)*bar | RegExpSequence | +| regexp.cpp:59:21:59:23 | foo | RegExpConstant,RegExpNormalChar | +| regexp.cpp:59:26:59:28 | bar | RegExpConstant,RegExpNormalChar | +| regexp.cpp:60:20:60:21 | fo | RegExpConstant,RegExpNormalChar | +| regexp.cpp:60:20:60:28 | fo(o\|b)ar | RegExpSequence | +| regexp.cpp:60:22:60:26 | (o\|b) | RegExpGroup | +| regexp.cpp:60:23:60:23 | o | RegExpConstant,RegExpNormalChar | +| regexp.cpp:60:23:60:25 | o\|b | RegExpAlt | +| regexp.cpp:60:25:60:25 | b | RegExpConstant,RegExpNormalChar | +| regexp.cpp:60:27:60:28 | ar | RegExpConstant,RegExpNormalChar | +| regexp.cpp:61:20:61:27 | (a\|b\|cd) | RegExpGroup | +| regexp.cpp:61:20:61:28 | (a\|b\|cd)e | RegExpSequence | +| regexp.cpp:61:21:61:21 | a | RegExpConstant,RegExpNormalChar | +| regexp.cpp:61:21:61:26 | a\|b\|cd | RegExpAlt | +| regexp.cpp:61:23:61:23 | b | RegExpConstant,RegExpNormalChar | +| regexp.cpp:61:25:61:26 | cd | RegExpConstant,RegExpNormalChar | +| regexp.cpp:61:28:61:28 | e | RegExpConstant,RegExpNormalChar | +| regexp.cpp:62:20:62:25 | (?::+) | RegExpGroup | +| regexp.cpp:62:20:62:27 | (?::+)\\w | RegExpSequence | +| regexp.cpp:62:23:62:23 | : | RegExpConstant,RegExpNormalChar | +| regexp.cpp:62:23:62:24 | :+ | RegExpPlus | +| regexp.cpp:62:26:62:27 | \\w | RegExpCharacterClassEscape | +| regexp.cpp:65:19:65:28 | (?\\w+) | RegExpGroup | +| regexp.cpp:65:25:65:26 | \\w | RegExpCharacterClassEscape | +| regexp.cpp:65:25:65:27 | \\w+ | RegExpPlus | +| regexp.cpp:66:19:66:29 | (?'foo'fo+) | RegExpGroup | +| regexp.cpp:66:26:66:26 | f | RegExpConstant,RegExpNormalChar | +| regexp.cpp:66:26:66:28 | fo+ | RegExpSequence | +| regexp.cpp:66:27:66:27 | o | RegExpConstant,RegExpNormalChar | +| regexp.cpp:66:27:66:28 | o+ | RegExpPlus | +| regexp.cpp:69:21:69:24 | (a+) | RegExpGroup | +| regexp.cpp:69:21:69:28 | (a+)b+\\1 | RegExpSequence | +| regexp.cpp:69:22:69:22 | a | RegExpConstant,RegExpNormalChar | +| regexp.cpp:69:22:69:23 | a+ | RegExpPlus | +| regexp.cpp:69:25:69:25 | b | RegExpConstant,RegExpNormalChar | +| regexp.cpp:69:25:69:26 | b+ | RegExpPlus | +| regexp.cpp:69:27:69:28 | \\1 | RegExpBackRef | +| regexp.cpp:70:21:70:30 | (?q+) | RegExpGroup | +| regexp.cpp:70:21:70:41 | (?q+)\\s+\\k+ | RegExpSequence | +| regexp.cpp:70:28:70:28 | q | RegExpConstant,RegExpNormalChar | +| regexp.cpp:70:28:70:29 | q+ | RegExpPlus | +| regexp.cpp:70:31:70:32 | \\s | RegExpCharacterClassEscape | +| regexp.cpp:70:31:70:33 | \\s+ | RegExpPlus | +| regexp.cpp:70:34:70:40 | \\k | RegExpBackRef | +| regexp.cpp:70:34:70:41 | \\k+ | RegExpPlus | +| regexp.cpp:73:21:73:28 | \\p{Word} | RegExpNamedCharacterProperty | +| regexp.cpp:73:21:73:29 | \\p{Word}* | RegExpStar | +| regexp.cpp:74:21:74:29 | \\P{Digit} | RegExpNamedCharacterProperty | +| regexp.cpp:74:21:74:30 | \\P{Digit}+ | RegExpPlus | +| regexp.cpp:75:21:75:30 | \\p{^Alnum} | RegExpNamedCharacterProperty | +| regexp.cpp:75:21:75:35 | \\p{^Alnum}{2,3} | RegExpRange | +| regexp.cpp:76:21:76:34 | [a-f\\p{Digit}] | RegExpCharacterClass | +| regexp.cpp:76:21:76:35 | [a-f\\p{Digit}]+ | RegExpPlus | +| regexp.cpp:76:22:76:22 | a | RegExpConstant,RegExpNormalChar | +| regexp.cpp:76:22:76:24 | a-f | RegExpCharacterRange | +| regexp.cpp:76:24:76:24 | f | RegExpConstant,RegExpNormalChar | +| regexp.cpp:76:25:76:33 | \\p{Digit} | RegExpNamedCharacterProperty | +| regexp.cpp:79:22:79:32 | [[:alpha:]] | RegExpCharacterClass | +| regexp.cpp:79:22:79:43 | [[:alpha:]][[:digit:]] | RegExpSequence | +| regexp.cpp:79:23:79:31 | [:alpha:] | RegExpNamedCharacterProperty | +| regexp.cpp:79:33:79:43 | [[:digit:]] | RegExpCharacterClass | +| regexp.cpp:79:34:79:42 | [:digit:] | RegExpNamedCharacterProperty | +| regexp.cpp:82:22:82:41 | [[:alpha:][:digit:]] | RegExpCharacterClass | +| regexp.cpp:82:23:82:31 | [:alpha:] | RegExpNamedCharacterProperty | +| regexp.cpp:82:32:82:40 | [:digit:] | RegExpNamedCharacterProperty | +| regexp.cpp:85:22:85:38 | [A-F[:digit:]a-f] | RegExpCharacterClass | +| regexp.cpp:85:23:85:23 | A | RegExpConstant,RegExpNormalChar | +| regexp.cpp:85:23:85:25 | A-F | RegExpCharacterRange | +| regexp.cpp:85:25:85:25 | F | RegExpConstant,RegExpNormalChar | +| regexp.cpp:85:26:85:34 | [:digit:] | RegExpNamedCharacterProperty | +| regexp.cpp:85:35:85:35 | a | RegExpConstant,RegExpNormalChar | +| regexp.cpp:85:35:85:37 | a-f | RegExpCharacterRange | +| regexp.cpp:85:37:85:37 | f | RegExpConstant,RegExpNormalChar | +| regexp.cpp:88:22:88:30 | [:digit:] | RegExpNamedCharacterProperty | +| regexp.cpp:91:19:91:24 | \\u{987 | RegExpConstant,RegExpEscape | regExpNormalCharValue -| regexp.rb:5:2:5:4 | abc | abc | -| regexp.rb:8:2:8:2 | a | a | -| regexp.rb:8:4:8:4 | b | b | -| regexp.rb:8:6:8:6 | c | c | -| regexp.rb:8:8:8:8 | d | d | -| regexp.rb:9:2:9:2 | a | a | -| regexp.rb:10:2:10:2 | a | a | -| regexp.rb:11:2:11:2 | a | a | -| regexp.rb:12:2:12:2 | a | a | -| regexp.rb:15:2:15:4 | foo | foo | -| regexp.rb:15:6:15:8 | bar | bar | -| regexp.rb:18:3:18:3 | a | a | -| regexp.rb:18:4:18:4 | b | b | -| regexp.rb:18:5:18:5 | c | c | -| regexp.rb:19:3:19:3 | a | a | -| regexp.rb:19:5:19:5 | f | f | -| regexp.rb:19:6:19:6 | A | A | -| regexp.rb:19:8:19:8 | F | F | -| regexp.rb:19:9:19:9 | 0 | 0 | -| regexp.rb:19:11:19:11 | 9 | 9 | -| regexp.rb:19:12:19:12 | _ | _ | -| regexp.rb:20:5:20:5 | + | + | -| regexp.rb:20:6:20:6 | - | - | -| regexp.rb:20:9:20:10 | \\d | d | -| regexp.rb:21:3:21:4 | \\w | w | -| regexp.rb:22:2:22:3 | \\[ | [ | -| regexp.rb:22:4:22:5 | \\] | ] | -| regexp.rb:22:7:22:7 | 1 | 1 | -| regexp.rb:22:8:22:8 | 2 | 2 | -| regexp.rb:22:9:22:9 | 3 | 3 | -| regexp.rb:23:4:23:4 | A | A | -| regexp.rb:23:6:23:6 | Z | Z | -| regexp.rb:24:3:24:3 | ] | ] | -| regexp.rb:25:4:25:4 | ] | ] | -| regexp.rb:26:4:26:4 | - | - | -| regexp.rb:27:3:27:3 | \| | \| | -| regexp.rb:30:3:30:3 | [ | [ | -| regexp.rb:30:4:30:4 | a | a | -| regexp.rb:30:6:30:6 | f | f | -| regexp.rb:30:8:30:11 | A-F] | A-F] | -| regexp.rb:35:2:35:3 | \\w | w | -| regexp.rb:35:5:35:6 | \\W | W | -| regexp.rb:36:2:36:3 | \\s | s | -| regexp.rb:36:4:36:5 | \\S | S | -| regexp.rb:37:2:37:3 | \\d | d | -| regexp.rb:37:4:37:5 | \\D | D | -| regexp.rb:38:2:38:3 | \\h | h | -| regexp.rb:38:4:38:5 | \\H | H | -| regexp.rb:39:2:39:3 | \\n | \n | -| regexp.rb:39:4:39:5 | \\r | \r | -| regexp.rb:39:6:39:7 | \\t | \t | -| regexp.rb:42:4:42:6 | abc | abc | -| regexp.rb:43:4:43:5 | !a | !a | -| regexp.rb:46:3:46:5 | foo | foo | -| regexp.rb:46:8:46:10 | bar | bar | -| regexp.rb:47:2:47:3 | fo | fo | -| regexp.rb:47:5:47:5 | o | o | -| regexp.rb:47:7:47:7 | b | b | -| regexp.rb:47:9:47:10 | ar | ar | -| regexp.rb:48:3:48:3 | a | a | -| regexp.rb:48:5:48:5 | b | b | -| regexp.rb:48:7:48:8 | cd | cd | -| regexp.rb:48:10:48:10 | e | e | -| regexp.rb:49:5:49:5 | : | : | -| regexp.rb:49:8:49:9 | \\w | w | -| regexp.rb:52:8:52:9 | \\w | w | -| regexp.rb:53:9:53:9 | f | f | -| regexp.rb:53:10:53:10 | o | o | -| regexp.rb:56:3:56:3 | a | a | -| regexp.rb:56:6:56:6 | b | b | -| regexp.rb:57:9:57:9 | q | q | -| regexp.rb:57:12:57:13 | \\s | s | -| regexp.rb:63:3:63:3 | a | a | -| regexp.rb:63:5:63:5 | f | f | -| regexp.rb:72:3:72:3 | A | A | -| regexp.rb:72:5:72:5 | F | F | -| regexp.rb:72:15:72:15 | a | a | -| regexp.rb:72:17:72:17 | f | f | -| regexp.rb:79:2:79:4 | abc | abc | -| regexp.rb:82:2:82:7 | \\u{987 | \u0987 | +| regexp.cpp:18:19:18:21 | abc | abc | +| regexp.cpp:21:20:21:20 | a | a | +| regexp.cpp:21:22:21:22 | b | b | +| regexp.cpp:21:24:21:24 | c | c | +| regexp.cpp:21:26:21:26 | d | d | +| regexp.cpp:22:20:22:20 | a | a | +| regexp.cpp:23:20:23:20 | a | a | +| regexp.cpp:24:20:24:20 | a | a | +| regexp.cpp:25:20:25:20 | a | a | +| regexp.cpp:28:19:28:21 | foo | foo | +| regexp.cpp:28:23:28:25 | bar | bar | +| regexp.cpp:31:20:31:20 | a | a | +| regexp.cpp:31:21:31:21 | b | b | +| regexp.cpp:31:22:31:22 | c | c | +| regexp.cpp:32:20:32:20 | a | a | +| regexp.cpp:32:22:32:22 | f | f | +| regexp.cpp:32:23:32:23 | A | A | +| regexp.cpp:32:25:32:25 | F | F | +| regexp.cpp:32:26:32:26 | 0 | 0 | +| regexp.cpp:32:28:32:28 | 9 | 9 | +| regexp.cpp:32:29:32:29 | _ | _ | +| regexp.cpp:33:22:33:22 | + | + | +| regexp.cpp:33:23:33:23 | - | - | +| regexp.cpp:33:26:33:27 | \\d | d | +| regexp.cpp:34:20:34:21 | \\w | w | +| regexp.cpp:35:19:35:20 | \\[ | [ | +| regexp.cpp:35:21:35:22 | \\] | ] | +| regexp.cpp:35:24:35:24 | 1 | 1 | +| regexp.cpp:35:25:35:25 | 2 | 2 | +| regexp.cpp:35:26:35:26 | 3 | 3 | +| regexp.cpp:36:21:36:21 | A | A | +| regexp.cpp:36:23:36:23 | Z | Z | +| regexp.cpp:37:20:37:20 | ] | ] | +| regexp.cpp:38:21:38:21 | ] | ] | +| regexp.cpp:39:21:39:21 | - | - | +| regexp.cpp:40:21:40:21 | \| | \| | +| regexp.cpp:43:23:43:23 | [ | [ | +| regexp.cpp:43:24:43:24 | a | a | +| regexp.cpp:43:26:43:26 | f | f | +| regexp.cpp:43:28:43:31 | A-F] | A-F] | +| regexp.cpp:48:21:48:22 | \\w | w | +| regexp.cpp:48:24:48:25 | \\W | W | +| regexp.cpp:49:21:49:22 | \\s | s | +| regexp.cpp:49:23:49:24 | \\S | S | +| regexp.cpp:50:21:50:22 | \\d | d | +| regexp.cpp:50:23:50:24 | \\D | D | +| regexp.cpp:51:21:51:22 | \\h | h | +| regexp.cpp:51:23:51:24 | \\H | H | +| regexp.cpp:52:21:52:22 | \\n | \n | +| regexp.cpp:52:23:52:24 | \\r | \r | +| regexp.cpp:52:25:52:26 | \\t | \t | +| regexp.cpp:55:22:55:24 | abc | abc | +| regexp.cpp:56:22:56:23 | !a | !a | +| regexp.cpp:59:21:59:23 | foo | foo | +| regexp.cpp:59:26:59:28 | bar | bar | +| regexp.cpp:60:20:60:21 | fo | fo | +| regexp.cpp:60:23:60:23 | o | o | +| regexp.cpp:60:25:60:25 | b | b | +| regexp.cpp:60:27:60:28 | ar | ar | +| regexp.cpp:61:21:61:21 | a | a | +| regexp.cpp:61:23:61:23 | b | b | +| regexp.cpp:61:25:61:26 | cd | cd | +| regexp.cpp:61:28:61:28 | e | e | +| regexp.cpp:62:23:62:23 | : | : | +| regexp.cpp:62:26:62:27 | \\w | w | +| regexp.cpp:65:25:65:26 | \\w | w | +| regexp.cpp:66:26:66:26 | f | f | +| regexp.cpp:66:27:66:27 | o | o | +| regexp.cpp:69:22:69:22 | a | a | +| regexp.cpp:69:25:69:25 | b | b | +| regexp.cpp:70:28:70:28 | q | q | +| regexp.cpp:70:31:70:32 | \\s | s | +| regexp.cpp:76:22:76:22 | a | a | +| regexp.cpp:76:24:76:24 | f | f | +| regexp.cpp:85:23:85:23 | A | A | +| regexp.cpp:85:25:85:25 | F | F | +| regexp.cpp:85:35:85:35 | a | a | +| regexp.cpp:85:37:85:37 | f | f | +| regexp.cpp:91:19:91:24 | \\u{987 | \u0987 | diff --git a/cpp/ql/test/library-tests/regex/regexp.ql b/cpp/ql/test/library-tests/regex/regexp.ql index e167cb1a7bb0..a29717199e24 100644 --- a/cpp/ql/test/library-tests/regex/regexp.ql +++ b/cpp/ql/test/library-tests/regex/regexp.ql @@ -1,5 +1,11 @@ +import semmle.code.cpp.regex.internal.ParseRegExp import semmle.code.cpp.regex.RegexTreeView +// Stop gap for missing flow configs +class RegExpTest extends RegExp { + RegExpTest() { any() } +} + query predicate groupName(RegExpGroup g, string name) { name = g.getName() } query predicate groupNumber(RegExpGroup g, int number) { number = g.getNumber() } From 7b2ce2484fd43f88c97be015232548283b67e7d9 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 23 Jul 2026 10:01:18 +0000 Subject: [PATCH 05/26] C++: Add location tests for all literal prefixes (pre-fix) --- .../library-tests/regex/locations.expected | 0 cpp/ql/test/library-tests/regex/locations.ql | 5 +++ .../test/library-tests/regex/parse.expected | 33 +++++++++++++++++++ cpp/ql/test/library-tests/regex/regexp.cpp | 20 +++++++++-- .../test/library-tests/regex/regexp.expected | 29 ++++++++++++++++ 5 files changed, 84 insertions(+), 3 deletions(-) create mode 100644 cpp/ql/test/library-tests/regex/locations.expected create mode 100644 cpp/ql/test/library-tests/regex/locations.ql diff --git a/cpp/ql/test/library-tests/regex/locations.expected b/cpp/ql/test/library-tests/regex/locations.expected new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/cpp/ql/test/library-tests/regex/locations.ql b/cpp/ql/test/library-tests/regex/locations.ql new file mode 100644 index 000000000000..f102f98a1b0a --- /dev/null +++ b/cpp/ql/test/library-tests/regex/locations.ql @@ -0,0 +1,5 @@ +import semmle.code.cpp.regex.RegexTreeView + +from RegExpTerm t, string file, int sl, int sc, int el, int ec +where t.isRootTerm() and t.hasLocationInfo(file, sl, sc, el, ec) +select t, file, sl, sc, el, ec diff --git a/cpp/ql/test/library-tests/regex/parse.expected b/cpp/ql/test/library-tests/regex/parse.expected index 13d74f0e5616..55d22c1b5fd9 100644 --- a/cpp/ql/test/library-tests/regex/parse.expected +++ b/cpp/ql/test/library-tests/regex/parse.expected @@ -485,3 +485,36 @@ regexp.cpp: # 88| [RegExpNamedCharacterProperty] [:digit:] # 91| [RegExpConstant, RegExpEscape] \u{987 + +# 94| [RegExpConstant, RegExpNormalChar] a + +# 94| [RegExpSequence] a\nb +#-----| 0 -> [RegExpConstant, RegExpNormalChar] a +#-----| 1 -> [RegExpConstant, RegExpEscape] \n +#-----| 2 -> [RegExpConstant, RegExpNormalChar] b + +# 94| [RegExpConstant, RegExpEscape] \n + +# 94| [RegExpConstant, RegExpNormalChar] b + +# 95| [RegExpConstant, RegExpNormalChar] abc + +# 96| [RegExpConstant, RegExpNormalChar] abc + +# 97| [RegExpConstant, RegExpNormalChar] abc + +# 98| [RegExpConstant, RegExpNormalChar] abc + +# 99| [RegExpConstant, RegExpNormalChar] abc + +# 100| [RegExpConstant, RegExpNormalChar] abc + +# 101| [RegExpConstant, RegExpNormalChar] abc + +# 102| [RegExpConstant, RegExpNormalChar] abc + +# 103| [RegExpConstant, RegExpNormalChar] abc + +# 104| [RegExpConstant, RegExpNormalChar] abc + +# 105| [RegExpConstant, RegExpNormalChar] abc diff --git a/cpp/ql/test/library-tests/regex/regexp.cpp b/cpp/ql/test/library-tests/regex/regexp.cpp index d0ba8099db5a..63bb73d32445 100644 --- a/cpp/ql/test/library-tests/regex/regexp.cpp +++ b/cpp/ql/test/library-tests/regex/regexp.cpp @@ -4,9 +4,9 @@ namespace std { template class basic_regex { public: - basic_regex(const char *s) {} - basic_regex(const char *s, int flags) {} - basic_regex &assign(const char *s) { return *this; } + basic_regex(const CharT *s) {} + basic_regex(const CharT *s, int flags) {} + basic_regex &assign(const CharT *s) { return *this; } }; typedef basic_regex regex; } // namespace std @@ -89,3 +89,17 @@ std::regex r_posix4("[:digit:]"); // unicode std::regex r_uni("\\u{9879}"); + +// String literal spellings for location tests +std::regex r_loc_plain("a\\nb"); +std::basic_regex r_loc_L(L"abc"); +std::basic_regex r_loc_u8(u8"abc"); +std::basic_regex r_loc_u(u"abc"); +std::basic_regex r_loc_U(U"abc"); +std::regex r_loc_R(R"(abc)"); +std::basic_regex r_loc_LR(LR"(abc)"); +std::basic_regex r_loc_u8R(u8R"(abc)"); +std::basic_regex r_loc_uR(uR"(abc)"); +std::basic_regex r_loc_UR(UR"(abc)"); +std::regex r_loc_Rx(R"x(abc)x"); +std::regex r_loc_Rfoo(R"foo(abc)foo"); diff --git a/cpp/ql/test/library-tests/regex/regexp.expected b/cpp/ql/test/library-tests/regex/regexp.expected index 6b2409e7c7c0..9cdc27438429 100644 --- a/cpp/ql/test/library-tests/regex/regexp.expected +++ b/cpp/ql/test/library-tests/regex/regexp.expected @@ -186,6 +186,21 @@ term | regexp.cpp:85:37:85:37 | f | RegExpConstant,RegExpNormalChar | | regexp.cpp:88:22:88:30 | [:digit:] | RegExpNamedCharacterProperty | | regexp.cpp:91:19:91:24 | \\u{987 | RegExpConstant,RegExpEscape | +| regexp.cpp:94:25:94:25 | a | RegExpConstant,RegExpNormalChar | +| regexp.cpp:94:25:94:28 | a\\nb | RegExpSequence | +| regexp.cpp:94:26:94:27 | \\n | RegExpConstant,RegExpEscape | +| regexp.cpp:94:28:94:28 | b | RegExpConstant,RegExpNormalChar | +| regexp.cpp:95:36:95:38 | abc | RegExpConstant,RegExpNormalChar | +| regexp.cpp:96:34:96:36 | abc | RegExpConstant,RegExpNormalChar | +| regexp.cpp:97:37:97:39 | abc | RegExpConstant,RegExpNormalChar | +| regexp.cpp:98:37:98:39 | abc | RegExpConstant,RegExpNormalChar | +| regexp.cpp:99:21:99:23 | abc | RegExpConstant,RegExpNormalChar | +| regexp.cpp:100:37:100:39 | abc | RegExpConstant,RegExpNormalChar | +| regexp.cpp:101:35:101:37 | abc | RegExpConstant,RegExpNormalChar | +| regexp.cpp:102:38:102:40 | abc | RegExpConstant,RegExpNormalChar | +| regexp.cpp:103:38:103:40 | abc | RegExpConstant,RegExpNormalChar | +| regexp.cpp:104:22:104:24 | abc | RegExpConstant,RegExpNormalChar | +| regexp.cpp:105:24:105:26 | abc | RegExpConstant,RegExpNormalChar | regExpNormalCharValue | regexp.cpp:18:19:18:21 | abc | abc | | regexp.cpp:21:20:21:20 | a | a | @@ -266,3 +281,17 @@ regExpNormalCharValue | regexp.cpp:85:35:85:35 | a | a | | regexp.cpp:85:37:85:37 | f | f | | regexp.cpp:91:19:91:24 | \\u{987 | \u0987 | +| regexp.cpp:94:25:94:25 | a | a | +| regexp.cpp:94:26:94:27 | \\n | \n | +| regexp.cpp:94:28:94:28 | b | b | +| regexp.cpp:95:36:95:38 | abc | abc | +| regexp.cpp:96:34:96:36 | abc | abc | +| regexp.cpp:97:37:97:39 | abc | abc | +| regexp.cpp:98:37:98:39 | abc | abc | +| regexp.cpp:99:21:99:23 | abc | abc | +| regexp.cpp:100:37:100:39 | abc | abc | +| regexp.cpp:101:35:101:37 | abc | abc | +| regexp.cpp:102:38:102:40 | abc | abc | +| regexp.cpp:103:38:103:40 | abc | abc | +| regexp.cpp:104:22:104:24 | abc | abc | +| regexp.cpp:105:24:105:26 | abc | abc | From 3444d2ef8770e77d8cf40868dff00860f151cf41 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 23 Jul 2026 10:02:55 +0000 Subject: [PATCH 06/26] C++: Fix regex term location offsets for all string literal spellings --- .../semmle/code/cpp/regex/RegexTreeView.qll | 21 +- .../test/library-tests/regex/parse.expected | 651 +++++++++--------- .../test/library-tests/regex/regexp.expected | 586 ++++++++-------- 3 files changed, 636 insertions(+), 622 deletions(-) diff --git a/cpp/ql/lib/semmle/code/cpp/regex/RegexTreeView.qll b/cpp/ql/lib/semmle/code/cpp/regex/RegexTreeView.qll index a0a116f2fe01..c91b588e51a0 100644 --- a/cpp/ql/lib/semmle/code/cpp/regex/RegexTreeView.qll +++ b/cpp/ql/lib/semmle/code/cpp/regex/RegexTreeView.qll @@ -215,10 +215,25 @@ private module Impl implements RegexTreeViewSig { predicate hasLocationInfo( string filepath, int startline, int startcolumn, int endline, int endcolumn ) { - exists(int re_start | + exists(int re_start, int contentStartOffset, string valueText | re.getLocation().hasLocationInfo(filepath, startline, re_start, endline, _) and - startcolumn = re_start + 1 + start and - endcolumn = re_start + 1 + end - 1 + valueText = re.getValueText() and + ( + valueText.regexpMatch("^\\s*(u8|L|u|U)?R\".*") and + exists(string prefix, string delimiter | + prefix = valueText.regexpCapture("^\\s*(u8|L|u|U)?R\"", 1) and + delimiter = valueText.regexpCapture("^\\s*(u8|L|u|U)?R\"([^()]*)\\(", 2) and + contentStartOffset = prefix.length() + delimiter.length() + 3 + ) + or + valueText.regexpMatch("^\\s*(u8|L|u|U)?\".*") and + exists(string prefix | + prefix = valueText.regexpCapture("^\\s*(u8|L|u|U)?\"", 1) and + contentStartOffset = prefix.length() + 1 + ) + ) and + startcolumn = re_start + contentStartOffset + start and + endcolumn = re_start + contentStartOffset + end - 1 ) } diff --git a/cpp/ql/test/library-tests/regex/parse.expected b/cpp/ql/test/library-tests/regex/parse.expected index 55d22c1b5fd9..1f92debd8e5c 100644 --- a/cpp/ql/test/library-tests/regex/parse.expected +++ b/cpp/ql/test/library-tests/regex/parse.expected @@ -1,520 +1,519 @@ -regexp.cpp: -# 18| [RegExpConstant, RegExpNormalChar] abc +#-----| [RegExpConstant, RegExpNormalChar] abc -# 21| [RegExpConstant, RegExpNormalChar] a +#-----| [RegExpConstant, RegExpNormalChar] abc -# 21| [RegExpStar] a* -#-----| 0 -> [RegExpConstant, RegExpNormalChar] a +#-----| [RegExpConstant, RegExpNormalChar] abc -# 21| [RegExpSequence] a*b+c?d -#-----| 0 -> [RegExpStar] a* -#-----| 1 -> [RegExpPlus] b+ -#-----| 2 -> [RegExpOpt] c? -#-----| 3 -> [RegExpConstant, RegExpNormalChar] d +#-----| [RegExpConstant, RegExpNormalChar] abc -# 21| [RegExpConstant, RegExpNormalChar] b +#-----| [RegExpConstant, RegExpNormalChar] abc -# 21| [RegExpPlus] b+ -#-----| 0 -> [RegExpConstant, RegExpNormalChar] b +#-----| [RegExpConstant, RegExpNormalChar] abc -# 21| [RegExpConstant, RegExpNormalChar] c +#-----| [RegExpConstant, RegExpNormalChar] abc -# 21| [RegExpOpt] c? -#-----| 0 -> [RegExpConstant, RegExpNormalChar] c +#-----| [RegExpConstant, RegExpNormalChar] abc -# 21| [RegExpConstant, RegExpNormalChar] d +#-----| [RegExpConstant, RegExpNormalChar] abc -# 22| [RegExpConstant, RegExpNormalChar] a +#-----| [RegExpConstant, RegExpNormalChar] abc -# 22| [RegExpRange] a{4,8} -#-----| 0 -> [RegExpConstant, RegExpNormalChar] a +#-----| [RegExpConstant, RegExpNormalChar] abc -# 23| [RegExpConstant, RegExpNormalChar] a +#-----| [RegExpConstant, RegExpNormalChar] a -# 23| [RegExpRange] a{,8} -#-----| 0 -> [RegExpConstant, RegExpNormalChar] a +#-----| [RegExpConstant, RegExpEscape] \n -# 24| [RegExpConstant, RegExpNormalChar] a +#-----| [RegExpConstant, RegExpNormalChar] b -# 24| [InfiniteRepetitionQuantifier, RegExpRange] a{3,} -#-----| 0 -> [RegExpConstant, RegExpNormalChar] a +#-----| [RegExpConstant, RegExpEscape] \u{987 -# 25| [RegExpConstant, RegExpNormalChar] a +#-----| [RegExpConstant, RegExpNormalChar] A -# 25| [RegExpRange] a{7} -#-----| 0 -> [RegExpConstant, RegExpNormalChar] a +#-----| [RegExpConstant, RegExpNormalChar] F -# 28| [RegExpConstant, RegExpNormalChar] foo +#-----| [RegExpConstant, RegExpNormalChar] a -# 28| [RegExpAlt] foo|bar -#-----| 0 -> [RegExpConstant, RegExpNormalChar] foo -#-----| 1 -> [RegExpConstant, RegExpNormalChar] bar +#-----| [RegExpConstant, RegExpNormalChar] f -# 28| [RegExpConstant, RegExpNormalChar] bar +#-----| [RegExpConstant, RegExpNormalChar] a -# 31| [RegExpCharacterClass] [abc] -#-----| 0 -> [RegExpConstant, RegExpNormalChar] a -#-----| 1 -> [RegExpConstant, RegExpNormalChar] b -#-----| 2 -> [RegExpConstant, RegExpNormalChar] c +#-----| [RegExpConstant, RegExpNormalChar] f -# 31| [RegExpConstant, RegExpNormalChar] a +#-----| [RegExpConstant, RegExpNormalChar] q -# 31| [RegExpConstant, RegExpNormalChar] b +#-----| [RegExpCharacterClassEscape] \s -# 31| [RegExpConstant, RegExpNormalChar] c +#-----| [RegExpConstant, RegExpNormalChar] a -# 32| [RegExpCharacterClass] [a-fA-F0-9_] -#-----| 0 -> [RegExpCharacterRange] a-f -#-----| 1 -> [RegExpCharacterRange] A-F -#-----| 2 -> [RegExpCharacterRange] 0-9 -#-----| 3 -> [RegExpConstant, RegExpNormalChar] _ +#-----| [RegExpConstant, RegExpNormalChar] b -# 32| [RegExpConstant, RegExpNormalChar] a +#-----| [RegExpConstant, RegExpNormalChar] f -# 32| [RegExpCharacterRange] a-f -#-----| 0 -> [RegExpConstant, RegExpNormalChar] a -#-----| 1 -> [RegExpConstant, RegExpNormalChar] f +#-----| [RegExpConstant, RegExpNormalChar] o -# 32| [RegExpConstant, RegExpNormalChar] f +#-----| [RegExpCharacterClassEscape] \w -# 32| [RegExpConstant, RegExpNormalChar] A +#-----| [RegExpConstant, RegExpNormalChar] : -# 32| [RegExpCharacterRange] A-F -#-----| 0 -> [RegExpConstant, RegExpNormalChar] A -#-----| 1 -> [RegExpConstant, RegExpNormalChar] F +#-----| [RegExpCharacterClassEscape] \w -# 32| [RegExpConstant, RegExpNormalChar] F +#-----| [RegExpConstant, RegExpNormalChar] a -# 32| [RegExpConstant, RegExpNormalChar] 0 +#-----| [RegExpConstant, RegExpNormalChar] b -# 32| [RegExpCharacterRange] 0-9 -#-----| 0 -> [RegExpConstant, RegExpNormalChar] 0 -#-----| 1 -> [RegExpConstant, RegExpNormalChar] 9 +#-----| [RegExpConstant, RegExpNormalChar] cd -# 32| [RegExpConstant, RegExpNormalChar] 9 +#-----| [RegExpConstant, RegExpNormalChar] e -# 32| [RegExpConstant, RegExpNormalChar] _ +#-----| [RegExpConstant, RegExpNormalChar] fo -# 33| [RegExpCaret] \A +#-----| [RegExpConstant, RegExpNormalChar] o -# 33| [RegExpSequence] \A[+-]?\d+ -#-----| 0 -> [RegExpCaret] \A -#-----| 1 -> [RegExpOpt] [+-]? -#-----| 2 -> [RegExpPlus] \d+ +#-----| [RegExpConstant, RegExpNormalChar] b -# 33| [RegExpCharacterClass] [+-] -#-----| 0 -> [RegExpConstant, RegExpNormalChar] + -#-----| 1 -> [RegExpConstant, RegExpNormalChar] - +#-----| [RegExpConstant, RegExpNormalChar] ar -# 33| [RegExpOpt] [+-]? -#-----| 0 -> [RegExpCharacterClass] [+-] +#-----| [RegExpConstant, RegExpNormalChar] foo -# 33| [RegExpConstant, RegExpNormalChar] + +#-----| [RegExpConstant, RegExpNormalChar] bar -# 33| [RegExpConstant, RegExpNormalChar] - +#-----| [RegExpConstant, RegExpNormalChar] !a -# 33| [RegExpCharacterClassEscape] \d +#-----| [RegExpConstant, RegExpNormalChar] abc -# 33| [RegExpPlus] \d+ -#-----| 0 -> [RegExpCharacterClassEscape] \d +#-----| [RegExpConstant, RegExpEscape] \n -# 34| [RegExpCharacterClass] [\w] -#-----| 0 -> [RegExpCharacterClassEscape] \w +#-----| [RegExpConstant, RegExpEscape] \r -# 34| [RegExpPlus] [\w]+ -#-----| 0 -> [RegExpCharacterClass] [\w] +#-----| [RegExpConstant, RegExpEscape] \t -# 34| [RegExpCharacterClassEscape] \w +#-----| [RegExpCharacterClassEscape] \h -# 35| [RegExpConstant, RegExpEscape] \[ +#-----| [RegExpCharacterClassEscape] \H -# 35| [RegExpSequence] \[\][123] -#-----| 0 -> [RegExpConstant, RegExpEscape] \[ -#-----| 1 -> [RegExpConstant, RegExpEscape] \] -#-----| 2 -> [RegExpCharacterClass] [123] +#-----| [RegExpCharacterClassEscape] \d -# 35| [RegExpConstant, RegExpEscape] \] +#-----| [RegExpCharacterClassEscape] \D -# 35| [RegExpCharacterClass] [123] -#-----| 0 -> [RegExpConstant, RegExpNormalChar] 1 -#-----| 1 -> [RegExpConstant, RegExpNormalChar] 2 -#-----| 2 -> [RegExpConstant, RegExpNormalChar] 3 +#-----| [RegExpCharacterClassEscape] \s -# 35| [RegExpConstant, RegExpNormalChar] 1 +#-----| [RegExpCharacterClassEscape] \S -# 35| [RegExpConstant, RegExpNormalChar] 2 +#-----| [RegExpCharacterClassEscape] \w -# 35| [RegExpConstant, RegExpNormalChar] 3 +#-----| [RegExpCharacterClassEscape] \W -# 36| [RegExpCharacterClass] [^A-Z] -#-----| 0 -> [RegExpCharacterRange] A-Z +#-----| [RegExpConstant, RegExpNormalChar] [ -# 36| [RegExpConstant, RegExpNormalChar] A +#-----| [RegExpConstant, RegExpNormalChar] a -# 36| [RegExpCharacterRange] A-Z -#-----| 0 -> [RegExpConstant, RegExpNormalChar] A -#-----| 1 -> [RegExpConstant, RegExpNormalChar] Z +#-----| [RegExpConstant, RegExpNormalChar] f -# 36| [RegExpConstant, RegExpNormalChar] Z +#-----| [RegExpConstant, RegExpNormalChar] A-F] -# 37| [RegExpCharacterClass] []] -#-----| 0 -> [RegExpConstant, RegExpNormalChar] ] +#-----| [RegExpConstant, RegExpNormalChar] | -# 37| [RegExpConstant, RegExpNormalChar] ] +#-----| [RegExpConstant, RegExpNormalChar] - -# 38| [RegExpCharacterClass] [^]] -#-----| 0 -> [RegExpConstant, RegExpNormalChar] ] +#-----| [RegExpConstant, RegExpNormalChar] ] -# 38| [RegExpConstant, RegExpNormalChar] ] +#-----| [RegExpConstant, RegExpNormalChar] ] -# 39| [RegExpCharacterClass] [^-] -#-----| 0 -> [RegExpConstant, RegExpNormalChar] - +#-----| [RegExpConstant, RegExpNormalChar] A -# 39| [RegExpConstant, RegExpNormalChar] - +#-----| [RegExpConstant, RegExpNormalChar] Z -# 40| [RegExpCharacterClass] [|] -#-----| 0 -> [RegExpConstant, RegExpNormalChar] | +#-----| [RegExpConstant, RegExpEscape] \[ -# 40| [RegExpConstant, RegExpNormalChar] | +#-----| [RegExpConstant, RegExpEscape] \] -# 43| [RegExpCharacterClass] [[a-f] -#-----| 0 -> [RegExpConstant, RegExpNormalChar] [ -#-----| 1 -> [RegExpCharacterRange] a-f +#-----| [RegExpConstant, RegExpNormalChar] 1 -# 43| [RegExpSequence] [[a-f]A-F] -#-----| 0 -> [RegExpCharacterClass] [[a-f] -#-----| 1 -> [RegExpConstant, RegExpNormalChar] A-F] +#-----| [RegExpConstant, RegExpNormalChar] 2 -# 43| [RegExpConstant, RegExpNormalChar] [ +#-----| [RegExpConstant, RegExpNormalChar] 3 -# 43| [RegExpConstant, RegExpNormalChar] a +#-----| [RegExpCharacterClassEscape] \w -# 43| [RegExpCharacterRange] a-f -#-----| 0 -> [RegExpConstant, RegExpNormalChar] a -#-----| 1 -> [RegExpConstant, RegExpNormalChar] f +#-----| [RegExpConstant, RegExpNormalChar] + -# 43| [RegExpConstant, RegExpNormalChar] f +#-----| [RegExpConstant, RegExpNormalChar] - -# 43| [RegExpConstant, RegExpNormalChar] A-F] +#-----| [RegExpCharacterClassEscape] \d -# 46| [RegExpDot] . +#-----| [RegExpConstant, RegExpNormalChar] a -# 46| [RegExpStar] .* -#-----| 0 -> [RegExpDot] . +#-----| [RegExpConstant, RegExpNormalChar] f -# 47| [RegExpDot] . +#-----| [RegExpConstant, RegExpNormalChar] A -# 47| [RegExpStar] .* -#-----| 0 -> [RegExpDot] . +#-----| [RegExpConstant, RegExpNormalChar] F -# 48| [RegExpCharacterClassEscape] \w +#-----| [RegExpConstant, RegExpNormalChar] 0 -# 48| [RegExpPlus] \w+ -#-----| 0 -> [RegExpCharacterClassEscape] \w +#-----| [RegExpConstant, RegExpNormalChar] 9 -# 48| [RegExpSequence] \w+\W -#-----| 0 -> [RegExpPlus] \w+ -#-----| 1 -> [RegExpCharacterClassEscape] \W +#-----| [RegExpConstant, RegExpNormalChar] _ -# 48| [RegExpCharacterClassEscape] \W +#-----| [RegExpConstant, RegExpNormalChar] a -# 49| [RegExpCharacterClassEscape] \s +#-----| [RegExpConstant, RegExpNormalChar] b -# 49| [RegExpSequence] \s\S -#-----| 0 -> [RegExpCharacterClassEscape] \s -#-----| 1 -> [RegExpCharacterClassEscape] \S +#-----| [RegExpConstant, RegExpNormalChar] c -# 49| [RegExpCharacterClassEscape] \S +#-----| [RegExpConstant, RegExpNormalChar] foo -# 50| [RegExpCharacterClassEscape] \d +#-----| [RegExpConstant, RegExpNormalChar] bar -# 50| [RegExpSequence] \d\D -#-----| 0 -> [RegExpCharacterClassEscape] \d -#-----| 1 -> [RegExpCharacterClassEscape] \D +#-----| [RegExpConstant, RegExpNormalChar] a -# 50| [RegExpCharacterClassEscape] \D +#-----| [RegExpConstant, RegExpNormalChar] a -# 51| [RegExpCharacterClassEscape] \h +#-----| [RegExpConstant, RegExpNormalChar] a -# 51| [RegExpSequence] \h\H -#-----| 0 -> [RegExpCharacterClassEscape] \h -#-----| 1 -> [RegExpCharacterClassEscape] \H +#-----| [RegExpConstant, RegExpNormalChar] a -# 51| [RegExpCharacterClassEscape] \H +#-----| [RegExpConstant, RegExpNormalChar] a -# 52| [RegExpConstant, RegExpEscape] \n +#-----| [RegExpConstant, RegExpNormalChar] b -# 52| [RegExpSequence] \n\r\t -#-----| 0 -> [RegExpConstant, RegExpEscape] \n -#-----| 1 -> [RegExpConstant, RegExpEscape] \r -#-----| 2 -> [RegExpConstant, RegExpEscape] \t - -# 52| [RegExpConstant, RegExpEscape] \r +#-----| [RegExpConstant, RegExpNormalChar] c -# 52| [RegExpConstant, RegExpEscape] \t +#-----| [RegExpConstant, RegExpNormalChar] d -# 55| [RegExpSpecialChar] \G +#-----| [RegExpConstant, RegExpNormalChar] abc -# 55| [RegExpSequence] \Gabc -#-----| 0 -> [RegExpSpecialChar] \G -#-----| 1 -> [RegExpConstant, RegExpNormalChar] abc +#-----| [RegExpSequence] a\nb +#-----| 0 -> [RegExpConstant, RegExpNormalChar] a +#-----| 1 -> [RegExpConstant, RegExpEscape] \n +#-----| 2 -> [RegExpConstant, RegExpNormalChar] b -# 55| [RegExpConstant, RegExpNormalChar] abc +#-----| [RegExpSequence] [[:alpha:]][[:digit:]] +#-----| 0 -> [RegExpCharacterClass] [[:alpha:]] +#-----| 1 -> [RegExpCharacterClass] [[:digit:]] -# 56| [RegExpSpecialChar] \b +#-----| [RegExpSequence] (?q+)\s+\k+ +#-----| 0 -> [RegExpGroup] (?q+) +#-----| 1 -> [RegExpPlus] \s+ +#-----| 2 -> [RegExpPlus] \k+ -# 56| [RegExpSequence] \b!a\B -#-----| 0 -> [RegExpSpecialChar] \b -#-----| 1 -> [RegExpConstant, RegExpNormalChar] !a -#-----| 2 -> [RegExpNonWordBoundary] \B +#-----| [RegExpSequence] (a+)b+\1 +#-----| 0 -> [RegExpGroup] (a+) +#-----| 1 -> [RegExpPlus] b+ +#-----| 2 -> [RegExpBackRef] \1 -# 56| [RegExpConstant, RegExpNormalChar] !a +#-----| [RegExpSequence] fo+ +#-----| 0 -> [RegExpConstant, RegExpNormalChar] f +#-----| 1 -> [RegExpPlus] o+ -# 56| [RegExpNonWordBoundary] \B +#-----| [RegExpSequence] (?::+)\w +#-----| 0 -> [RegExpGroup] (?::+) +#-----| 1 -> [RegExpCharacterClassEscape] \w -# 59| [RegExpGroup] (foo) -#-----| 0 -> [RegExpConstant, RegExpNormalChar] foo +#-----| [RegExpSequence] (a|b|cd)e +#-----| 0 -> [RegExpGroup] (a|b|cd) +#-----| 1 -> [RegExpConstant, RegExpNormalChar] e -# 59| [RegExpStar] (foo)* -#-----| 0 -> [RegExpGroup] (foo) +#-----| [RegExpSequence] fo(o|b)ar +#-----| 0 -> [RegExpConstant, RegExpNormalChar] fo +#-----| 1 -> [RegExpGroup] (o|b) +#-----| 2 -> [RegExpConstant, RegExpNormalChar] ar -# 59| [RegExpSequence] (foo)*bar +#-----| [RegExpSequence] (foo)*bar #-----| 0 -> [RegExpStar] (foo)* #-----| 1 -> [RegExpConstant, RegExpNormalChar] bar -# 59| [RegExpConstant, RegExpNormalChar] foo - -# 59| [RegExpConstant, RegExpNormalChar] bar +#-----| [RegExpSequence] \b!a\B +#-----| 0 -> [RegExpSpecialChar] \b +#-----| 1 -> [RegExpConstant, RegExpNormalChar] !a +#-----| 2 -> [RegExpNonWordBoundary] \B -# 60| [RegExpConstant, RegExpNormalChar] fo +#-----| [RegExpSequence] \Gabc +#-----| 0 -> [RegExpSpecialChar] \G +#-----| 1 -> [RegExpConstant, RegExpNormalChar] abc -# 60| [RegExpSequence] fo(o|b)ar -#-----| 0 -> [RegExpConstant, RegExpNormalChar] fo -#-----| 1 -> [RegExpGroup] (o|b) -#-----| 2 -> [RegExpConstant, RegExpNormalChar] ar +#-----| [RegExpSequence] \n\r\t +#-----| 0 -> [RegExpConstant, RegExpEscape] \n +#-----| 1 -> [RegExpConstant, RegExpEscape] \r +#-----| 2 -> [RegExpConstant, RegExpEscape] \t -# 60| [RegExpGroup] (o|b) -#-----| 0 -> [RegExpAlt] o|b +#-----| [RegExpSequence] \h\H +#-----| 0 -> [RegExpCharacterClassEscape] \h +#-----| 1 -> [RegExpCharacterClassEscape] \H -# 60| [RegExpConstant, RegExpNormalChar] o +#-----| [RegExpSequence] \d\D +#-----| 0 -> [RegExpCharacterClassEscape] \d +#-----| 1 -> [RegExpCharacterClassEscape] \D -# 60| [RegExpAlt] o|b -#-----| 0 -> [RegExpConstant, RegExpNormalChar] o -#-----| 1 -> [RegExpConstant, RegExpNormalChar] b +#-----| [RegExpSequence] \s\S +#-----| 0 -> [RegExpCharacterClassEscape] \s +#-----| 1 -> [RegExpCharacterClassEscape] \S -# 60| [RegExpConstant, RegExpNormalChar] b +#-----| [RegExpSequence] \w+\W +#-----| 0 -> [RegExpPlus] \w+ +#-----| 1 -> [RegExpCharacterClassEscape] \W -# 60| [RegExpConstant, RegExpNormalChar] ar +#-----| [RegExpSequence] [[a-f]A-F] +#-----| 0 -> [RegExpCharacterClass] [[a-f] +#-----| 1 -> [RegExpConstant, RegExpNormalChar] A-F] -# 61| [RegExpGroup] (a|b|cd) -#-----| 0 -> [RegExpAlt] a|b|cd +#-----| [RegExpSequence] \[\][123] +#-----| 0 -> [RegExpConstant, RegExpEscape] \[ +#-----| 1 -> [RegExpConstant, RegExpEscape] \] +#-----| 2 -> [RegExpCharacterClass] [123] -# 61| [RegExpSequence] (a|b|cd)e -#-----| 0 -> [RegExpGroup] (a|b|cd) -#-----| 1 -> [RegExpConstant, RegExpNormalChar] e +#-----| [RegExpSequence] \A[+-]?\d+ +#-----| 0 -> [RegExpCaret] \A +#-----| 1 -> [RegExpOpt] [+-]? +#-----| 2 -> [RegExpPlus] \d+ -# 61| [RegExpConstant, RegExpNormalChar] a +#-----| [RegExpSequence] a*b+c?d +#-----| 0 -> [RegExpStar] a* +#-----| 1 -> [RegExpPlus] b+ +#-----| 2 -> [RegExpOpt] c? +#-----| 3 -> [RegExpConstant, RegExpNormalChar] d -# 61| [RegExpAlt] a|b|cd -#-----| 0 -> [RegExpConstant, RegExpNormalChar] a -#-----| 1 -> [RegExpConstant, RegExpNormalChar] b -#-----| 2 -> [RegExpConstant, RegExpNormalChar] cd +#-----| [RegExpNamedCharacterProperty] [:digit:] -# 61| [RegExpConstant, RegExpNormalChar] b +#-----| [RegExpNamedCharacterProperty] [:digit:] -# 61| [RegExpConstant, RegExpNormalChar] cd +#-----| [RegExpNamedCharacterProperty] [:alpha:] -# 61| [RegExpConstant, RegExpNormalChar] e +#-----| [RegExpNamedCharacterProperty] [:digit:] -# 62| [RegExpGroup] (?::+) -#-----| 0 -> [RegExpPlus] :+ +#-----| [RegExpNamedCharacterProperty] [:alpha:] -# 62| [RegExpSequence] (?::+)\w -#-----| 0 -> [RegExpGroup] (?::+) -#-----| 1 -> [RegExpCharacterClassEscape] \w +#-----| [RegExpNamedCharacterProperty] [:digit:] -# 62| [RegExpConstant, RegExpNormalChar] : +#-----| [RegExpNamedCharacterProperty] \p{Digit} -# 62| [RegExpPlus] :+ -#-----| 0 -> [RegExpConstant, RegExpNormalChar] : +#-----| [RegExpNamedCharacterProperty] \p{^Alnum} -# 62| [RegExpCharacterClassEscape] \w +#-----| [RegExpNamedCharacterProperty] \P{Digit} -# 65| [RegExpGroup] (?\w+) -#-----| 0 -> [RegExpPlus] \w+ +#-----| [RegExpNamedCharacterProperty] \p{Word} -# 65| [RegExpCharacterClassEscape] \w +#-----| [RegExpBackRef] \k -# 65| [RegExpPlus] \w+ -#-----| 0 -> [RegExpCharacterClassEscape] \w +#-----| [RegExpBackRef] \1 -# 66| [RegExpGroup] (?'foo'fo+) -#-----| 0 -> [RegExpSequence] fo+ +#-----| [RegExpSpecialChar] \b -# 66| [RegExpConstant, RegExpNormalChar] f +#-----| [RegExpNonWordBoundary] \B -# 66| [RegExpSequence] fo+ -#-----| 0 -> [RegExpConstant, RegExpNormalChar] f -#-----| 1 -> [RegExpPlus] o+ +#-----| [RegExpSpecialChar] \G -# 66| [RegExpConstant, RegExpNormalChar] o +#-----| [RegExpDot] . -# 66| [RegExpPlus] o+ -#-----| 0 -> [RegExpConstant, RegExpNormalChar] o +#-----| [RegExpDot] . -# 69| [RegExpGroup] (a+) -#-----| 0 -> [RegExpPlus] a+ +#-----| [RegExpCaret] \A -# 69| [RegExpSequence] (a+)b+\1 -#-----| 0 -> [RegExpGroup] (a+) -#-----| 1 -> [RegExpPlus] b+ -#-----| 2 -> [RegExpBackRef] \1 +#-----| [RegExpGroup] (?q+) +#-----| 0 -> [RegExpPlus] q+ -# 69| [RegExpConstant, RegExpNormalChar] a +#-----| [RegExpGroup] (a+) +#-----| 0 -> [RegExpPlus] a+ -# 69| [RegExpPlus] a+ -#-----| 0 -> [RegExpConstant, RegExpNormalChar] a +#-----| [RegExpGroup] (?'foo'fo+) +#-----| 0 -> [RegExpSequence] fo+ -# 69| [RegExpConstant, RegExpNormalChar] b +#-----| [RegExpGroup] (?\w+) +#-----| 0 -> [RegExpPlus] \w+ -# 69| [RegExpPlus] b+ -#-----| 0 -> [RegExpConstant, RegExpNormalChar] b +#-----| [RegExpGroup] (?::+) +#-----| 0 -> [RegExpPlus] :+ -# 69| [RegExpBackRef] \1 +#-----| [RegExpGroup] (a|b|cd) +#-----| 0 -> [RegExpAlt] a|b|cd -# 70| [RegExpGroup] (?q+) -#-----| 0 -> [RegExpPlus] q+ +#-----| [RegExpGroup] (o|b) +#-----| 0 -> [RegExpAlt] o|b -# 70| [RegExpSequence] (?q+)\s+\k+ -#-----| 0 -> [RegExpGroup] (?q+) -#-----| 1 -> [RegExpPlus] \s+ -#-----| 2 -> [RegExpPlus] \k+ +#-----| [RegExpGroup] (foo) +#-----| 0 -> [RegExpConstant, RegExpNormalChar] foo -# 70| [RegExpConstant, RegExpNormalChar] q +#-----| [RegExpCharacterRange] A-F +#-----| 0 -> [RegExpConstant, RegExpNormalChar] A +#-----| 1 -> [RegExpConstant, RegExpNormalChar] F -# 70| [RegExpPlus] q+ -#-----| 0 -> [RegExpConstant, RegExpNormalChar] q +#-----| [RegExpCharacterRange] a-f +#-----| 0 -> [RegExpConstant, RegExpNormalChar] a +#-----| 1 -> [RegExpConstant, RegExpNormalChar] f -# 70| [RegExpCharacterClassEscape] \s +#-----| [RegExpCharacterRange] a-f +#-----| 0 -> [RegExpConstant, RegExpNormalChar] a +#-----| 1 -> [RegExpConstant, RegExpNormalChar] f -# 70| [RegExpPlus] \s+ -#-----| 0 -> [RegExpCharacterClassEscape] \s +#-----| [RegExpCharacterRange] a-f +#-----| 0 -> [RegExpConstant, RegExpNormalChar] a +#-----| 1 -> [RegExpConstant, RegExpNormalChar] f -# 70| [RegExpBackRef] \k +#-----| [RegExpCharacterRange] A-Z +#-----| 0 -> [RegExpConstant, RegExpNormalChar] A +#-----| 1 -> [RegExpConstant, RegExpNormalChar] Z -# 70| [RegExpPlus] \k+ -#-----| 0 -> [RegExpBackRef] \k +#-----| [RegExpCharacterRange] a-f +#-----| 0 -> [RegExpConstant, RegExpNormalChar] a +#-----| 1 -> [RegExpConstant, RegExpNormalChar] f -# 73| [RegExpNamedCharacterProperty] \p{Word} +#-----| [RegExpCharacterRange] A-F +#-----| 0 -> [RegExpConstant, RegExpNormalChar] A +#-----| 1 -> [RegExpConstant, RegExpNormalChar] F -# 73| [RegExpStar] \p{Word}* -#-----| 0 -> [RegExpNamedCharacterProperty] \p{Word} +#-----| [RegExpCharacterRange] 0-9 +#-----| 0 -> [RegExpConstant, RegExpNormalChar] 0 +#-----| 1 -> [RegExpConstant, RegExpNormalChar] 9 -# 74| [RegExpNamedCharacterProperty] \P{Digit} +#-----| [RegExpCharacterClass] [A-F[:digit:]a-f] +#-----| 0 -> [RegExpCharacterRange] A-F +#-----| 1 -> [RegExpNamedCharacterProperty] [:digit:] +#-----| 2 -> [RegExpCharacterRange] a-f -# 74| [RegExpPlus] \P{Digit}+ -#-----| 0 -> [RegExpNamedCharacterProperty] \P{Digit} +#-----| [RegExpCharacterClass] [[:alpha:][:digit:]] +#-----| 0 -> [RegExpNamedCharacterProperty] [:alpha:] +#-----| 1 -> [RegExpNamedCharacterProperty] [:digit:] -# 75| [RegExpNamedCharacterProperty] \p{^Alnum} +#-----| [RegExpCharacterClass] [[:alpha:]] +#-----| 0 -> [RegExpNamedCharacterProperty] [:alpha:] -# 75| [RegExpRange] \p{^Alnum}{2,3} -#-----| 0 -> [RegExpNamedCharacterProperty] \p{^Alnum} +#-----| [RegExpCharacterClass] [[:digit:]] +#-----| 0 -> [RegExpNamedCharacterProperty] [:digit:] -# 76| [RegExpCharacterClass] [a-f\p{Digit}] +#-----| [RegExpCharacterClass] [a-f\p{Digit}] #-----| 0 -> [RegExpCharacterRange] a-f #-----| 1 -> [RegExpNamedCharacterProperty] \p{Digit} -# 76| [RegExpPlus] [a-f\p{Digit}]+ -#-----| 0 -> [RegExpCharacterClass] [a-f\p{Digit}] +#-----| [RegExpCharacterClass] [[a-f] +#-----| 0 -> [RegExpConstant, RegExpNormalChar] [ +#-----| 1 -> [RegExpCharacterRange] a-f -# 76| [RegExpConstant, RegExpNormalChar] a +#-----| [RegExpCharacterClass] [|] +#-----| 0 -> [RegExpConstant, RegExpNormalChar] | -# 76| [RegExpCharacterRange] a-f -#-----| 0 -> [RegExpConstant, RegExpNormalChar] a -#-----| 1 -> [RegExpConstant, RegExpNormalChar] f +#-----| [RegExpCharacterClass] [^-] +#-----| 0 -> [RegExpConstant, RegExpNormalChar] - -# 76| [RegExpConstant, RegExpNormalChar] f +#-----| [RegExpCharacterClass] [^]] +#-----| 0 -> [RegExpConstant, RegExpNormalChar] ] -# 76| [RegExpNamedCharacterProperty] \p{Digit} +#-----| [RegExpCharacterClass] []] +#-----| 0 -> [RegExpConstant, RegExpNormalChar] ] -# 79| [RegExpCharacterClass] [[:alpha:]] -#-----| 0 -> [RegExpNamedCharacterProperty] [:alpha:] +#-----| [RegExpCharacterClass] [^A-Z] +#-----| 0 -> [RegExpCharacterRange] A-Z -# 79| [RegExpSequence] [[:alpha:]][[:digit:]] -#-----| 0 -> [RegExpCharacterClass] [[:alpha:]] -#-----| 1 -> [RegExpCharacterClass] [[:digit:]] +#-----| [RegExpCharacterClass] [123] +#-----| 0 -> [RegExpConstant, RegExpNormalChar] 1 +#-----| 1 -> [RegExpConstant, RegExpNormalChar] 2 +#-----| 2 -> [RegExpConstant, RegExpNormalChar] 3 -# 79| [RegExpNamedCharacterProperty] [:alpha:] +#-----| [RegExpCharacterClass] [\w] +#-----| 0 -> [RegExpCharacterClassEscape] \w -# 79| [RegExpCharacterClass] [[:digit:]] -#-----| 0 -> [RegExpNamedCharacterProperty] [:digit:] +#-----| [RegExpCharacterClass] [+-] +#-----| 0 -> [RegExpConstant, RegExpNormalChar] + +#-----| 1 -> [RegExpConstant, RegExpNormalChar] - -# 79| [RegExpNamedCharacterProperty] [:digit:] +#-----| [RegExpCharacterClass] [a-fA-F0-9_] +#-----| 0 -> [RegExpCharacterRange] a-f +#-----| 1 -> [RegExpCharacterRange] A-F +#-----| 2 -> [RegExpCharacterRange] 0-9 +#-----| 3 -> [RegExpConstant, RegExpNormalChar] _ -# 82| [RegExpCharacterClass] [[:alpha:][:digit:]] -#-----| 0 -> [RegExpNamedCharacterProperty] [:alpha:] -#-----| 1 -> [RegExpNamedCharacterProperty] [:digit:] +#-----| [RegExpCharacterClass] [abc] +#-----| 0 -> [RegExpConstant, RegExpNormalChar] a +#-----| 1 -> [RegExpConstant, RegExpNormalChar] b +#-----| 2 -> [RegExpConstant, RegExpNormalChar] c -# 82| [RegExpNamedCharacterProperty] [:alpha:] +#-----| [RegExpAlt] a|b|cd +#-----| 0 -> [RegExpConstant, RegExpNormalChar] a +#-----| 1 -> [RegExpConstant, RegExpNormalChar] b +#-----| 2 -> [RegExpConstant, RegExpNormalChar] cd -# 82| [RegExpNamedCharacterProperty] [:digit:] +#-----| [RegExpAlt] o|b +#-----| 0 -> [RegExpConstant, RegExpNormalChar] o +#-----| 1 -> [RegExpConstant, RegExpNormalChar] b -# 85| [RegExpCharacterClass] [A-F[:digit:]a-f] -#-----| 0 -> [RegExpCharacterRange] A-F -#-----| 1 -> [RegExpNamedCharacterProperty] [:digit:] -#-----| 2 -> [RegExpCharacterRange] a-f +#-----| [RegExpAlt] foo|bar +#-----| 0 -> [RegExpConstant, RegExpNormalChar] foo +#-----| 1 -> [RegExpConstant, RegExpNormalChar] bar -# 85| [RegExpConstant, RegExpNormalChar] A +#-----| [RegExpPlus] [a-f\p{Digit}]+ +#-----| 0 -> [RegExpCharacterClass] [a-f\p{Digit}] -# 85| [RegExpCharacterRange] A-F -#-----| 0 -> [RegExpConstant, RegExpNormalChar] A -#-----| 1 -> [RegExpConstant, RegExpNormalChar] F +#-----| [RegExpRange] \p{^Alnum}{2,3} +#-----| 0 -> [RegExpNamedCharacterProperty] \p{^Alnum} -# 85| [RegExpConstant, RegExpNormalChar] F +#-----| [RegExpPlus] \P{Digit}+ +#-----| 0 -> [RegExpNamedCharacterProperty] \P{Digit} -# 85| [RegExpNamedCharacterProperty] [:digit:] +#-----| [RegExpStar] \p{Word}* +#-----| 0 -> [RegExpNamedCharacterProperty] \p{Word} + +#-----| [RegExpPlus] q+ +#-----| 0 -> [RegExpConstant, RegExpNormalChar] q -# 85| [RegExpConstant, RegExpNormalChar] a +#-----| [RegExpPlus] \s+ +#-----| 0 -> [RegExpCharacterClassEscape] \s -# 85| [RegExpCharacterRange] a-f +#-----| [RegExpPlus] \k+ +#-----| 0 -> [RegExpBackRef] \k + +#-----| [RegExpPlus] a+ #-----| 0 -> [RegExpConstant, RegExpNormalChar] a -#-----| 1 -> [RegExpConstant, RegExpNormalChar] f -# 85| [RegExpConstant, RegExpNormalChar] f +#-----| [RegExpPlus] b+ +#-----| 0 -> [RegExpConstant, RegExpNormalChar] b -# 88| [RegExpNamedCharacterProperty] [:digit:] +#-----| [RegExpPlus] o+ +#-----| 0 -> [RegExpConstant, RegExpNormalChar] o -# 91| [RegExpConstant, RegExpEscape] \u{987 +#-----| [RegExpPlus] \w+ +#-----| 0 -> [RegExpCharacterClassEscape] \w -# 94| [RegExpConstant, RegExpNormalChar] a +#-----| [RegExpPlus] :+ +#-----| 0 -> [RegExpConstant, RegExpNormalChar] : -# 94| [RegExpSequence] a\nb -#-----| 0 -> [RegExpConstant, RegExpNormalChar] a -#-----| 1 -> [RegExpConstant, RegExpEscape] \n -#-----| 2 -> [RegExpConstant, RegExpNormalChar] b +#-----| [RegExpStar] (foo)* +#-----| 0 -> [RegExpGroup] (foo) -# 94| [RegExpConstant, RegExpEscape] \n +#-----| [RegExpPlus] \w+ +#-----| 0 -> [RegExpCharacterClassEscape] \w -# 94| [RegExpConstant, RegExpNormalChar] b +#-----| [RegExpStar] .* +#-----| 0 -> [RegExpDot] . -# 95| [RegExpConstant, RegExpNormalChar] abc +#-----| [RegExpStar] .* +#-----| 0 -> [RegExpDot] . -# 96| [RegExpConstant, RegExpNormalChar] abc +#-----| [RegExpPlus] [\w]+ +#-----| 0 -> [RegExpCharacterClass] [\w] -# 97| [RegExpConstant, RegExpNormalChar] abc +#-----| [RegExpOpt] [+-]? +#-----| 0 -> [RegExpCharacterClass] [+-] -# 98| [RegExpConstant, RegExpNormalChar] abc +#-----| [RegExpPlus] \d+ +#-----| 0 -> [RegExpCharacterClassEscape] \d -# 99| [RegExpConstant, RegExpNormalChar] abc +#-----| [RegExpRange] a{7} +#-----| 0 -> [RegExpConstant, RegExpNormalChar] a -# 100| [RegExpConstant, RegExpNormalChar] abc +#-----| [InfiniteRepetitionQuantifier, RegExpRange] a{3,} +#-----| 0 -> [RegExpConstant, RegExpNormalChar] a -# 101| [RegExpConstant, RegExpNormalChar] abc +#-----| [RegExpRange] a{,8} +#-----| 0 -> [RegExpConstant, RegExpNormalChar] a -# 102| [RegExpConstant, RegExpNormalChar] abc +#-----| [RegExpRange] a{4,8} +#-----| 0 -> [RegExpConstant, RegExpNormalChar] a -# 103| [RegExpConstant, RegExpNormalChar] abc +#-----| [RegExpStar] a* +#-----| 0 -> [RegExpConstant, RegExpNormalChar] a -# 104| [RegExpConstant, RegExpNormalChar] abc +#-----| [RegExpPlus] b+ +#-----| 0 -> [RegExpConstant, RegExpNormalChar] b -# 105| [RegExpConstant, RegExpNormalChar] abc +#-----| [RegExpOpt] c? +#-----| 0 -> [RegExpConstant, RegExpNormalChar] c diff --git a/cpp/ql/test/library-tests/regex/regexp.expected b/cpp/ql/test/library-tests/regex/regexp.expected index 9cdc27438429..e671353d19ff 100644 --- a/cpp/ql/test/library-tests/regex/regexp.expected +++ b/cpp/ql/test/library-tests/regex/regexp.expected @@ -1,297 +1,297 @@ groupName -| regexp.cpp:65:19:65:28 | (?\\w+) | id | -| regexp.cpp:66:19:66:29 | (?'foo'fo+) | foo | -| regexp.cpp:70:21:70:30 | (?q+) | qux | +| file://:0:0:0:0 | (?'foo'fo+) | foo | +| file://:0:0:0:0 | (?\\w+) | id | +| file://:0:0:0:0 | (?q+) | qux | groupNumber -| regexp.cpp:59:20:59:24 | (foo) | 1 | -| regexp.cpp:60:22:60:26 | (o\|b) | 1 | -| regexp.cpp:61:20:61:27 | (a\|b\|cd) | 1 | -| regexp.cpp:66:19:66:29 | (?'foo'fo+) | 1 | -| regexp.cpp:69:21:69:24 | (a+) | 1 | +| file://:0:0:0:0 | (?'foo'fo+) | 1 | +| file://:0:0:0:0 | (a+) | 1 | +| file://:0:0:0:0 | (a\|b\|cd) | 1 | +| file://:0:0:0:0 | (foo) | 1 | +| file://:0:0:0:0 | (o\|b) | 1 | term -| regexp.cpp:18:19:18:21 | abc | RegExpConstant,RegExpNormalChar | -| regexp.cpp:21:20:21:20 | a | RegExpConstant,RegExpNormalChar | -| regexp.cpp:21:20:21:21 | a* | RegExpStar | -| regexp.cpp:21:20:21:26 | a*b+c?d | RegExpSequence | -| regexp.cpp:21:22:21:22 | b | RegExpConstant,RegExpNormalChar | -| regexp.cpp:21:22:21:23 | b+ | RegExpPlus | -| regexp.cpp:21:24:21:24 | c | RegExpConstant,RegExpNormalChar | -| regexp.cpp:21:24:21:25 | c? | RegExpOpt | -| regexp.cpp:21:26:21:26 | d | RegExpConstant,RegExpNormalChar | -| regexp.cpp:22:20:22:20 | a | RegExpConstant,RegExpNormalChar | -| regexp.cpp:22:20:22:25 | a{4,8} | RegExpRange | -| regexp.cpp:23:20:23:20 | a | RegExpConstant,RegExpNormalChar | -| regexp.cpp:23:20:23:24 | a{,8} | RegExpRange | -| regexp.cpp:24:20:24:20 | a | RegExpConstant,RegExpNormalChar | -| regexp.cpp:24:20:24:24 | a{3,} | InfiniteRepetitionQuantifier,RegExpRange | -| regexp.cpp:25:20:25:20 | a | RegExpConstant,RegExpNormalChar | -| regexp.cpp:25:20:25:23 | a{7} | RegExpRange | -| regexp.cpp:28:19:28:21 | foo | RegExpConstant,RegExpNormalChar | -| regexp.cpp:28:19:28:25 | foo\|bar | RegExpAlt | -| regexp.cpp:28:23:28:25 | bar | RegExpConstant,RegExpNormalChar | -| regexp.cpp:31:19:31:23 | [abc] | RegExpCharacterClass | -| regexp.cpp:31:20:31:20 | a | RegExpConstant,RegExpNormalChar | -| regexp.cpp:31:21:31:21 | b | RegExpConstant,RegExpNormalChar | -| regexp.cpp:31:22:31:22 | c | RegExpConstant,RegExpNormalChar | -| regexp.cpp:32:19:32:30 | [a-fA-F0-9_] | RegExpCharacterClass | -| regexp.cpp:32:20:32:20 | a | RegExpConstant,RegExpNormalChar | -| regexp.cpp:32:20:32:22 | a-f | RegExpCharacterRange | -| regexp.cpp:32:22:32:22 | f | RegExpConstant,RegExpNormalChar | -| regexp.cpp:32:23:32:23 | A | RegExpConstant,RegExpNormalChar | -| regexp.cpp:32:23:32:25 | A-F | RegExpCharacterRange | -| regexp.cpp:32:25:32:25 | F | RegExpConstant,RegExpNormalChar | -| regexp.cpp:32:26:32:26 | 0 | RegExpConstant,RegExpNormalChar | -| regexp.cpp:32:26:32:28 | 0-9 | RegExpCharacterRange | -| regexp.cpp:32:28:32:28 | 9 | RegExpConstant,RegExpNormalChar | -| regexp.cpp:32:29:32:29 | _ | RegExpConstant,RegExpNormalChar | -| regexp.cpp:33:19:33:20 | \\A | RegExpCaret | -| regexp.cpp:33:19:33:28 | \\A[+-]?\\d+ | RegExpSequence | -| regexp.cpp:33:21:33:24 | [+-] | RegExpCharacterClass | -| regexp.cpp:33:21:33:25 | [+-]? | RegExpOpt | -| regexp.cpp:33:22:33:22 | + | RegExpConstant,RegExpNormalChar | -| regexp.cpp:33:23:33:23 | - | RegExpConstant,RegExpNormalChar | -| regexp.cpp:33:26:33:27 | \\d | RegExpCharacterClassEscape | -| regexp.cpp:33:26:33:28 | \\d+ | RegExpPlus | -| regexp.cpp:34:19:34:22 | [\\w] | RegExpCharacterClass | -| regexp.cpp:34:19:34:23 | [\\w]+ | RegExpPlus | -| regexp.cpp:34:20:34:21 | \\w | RegExpCharacterClassEscape | -| regexp.cpp:35:19:35:20 | \\[ | RegExpConstant,RegExpEscape | -| regexp.cpp:35:19:35:27 | \\[\\][123] | RegExpSequence | -| regexp.cpp:35:21:35:22 | \\] | RegExpConstant,RegExpEscape | -| regexp.cpp:35:23:35:27 | [123] | RegExpCharacterClass | -| regexp.cpp:35:24:35:24 | 1 | RegExpConstant,RegExpNormalChar | -| regexp.cpp:35:25:35:25 | 2 | RegExpConstant,RegExpNormalChar | -| regexp.cpp:35:26:35:26 | 3 | RegExpConstant,RegExpNormalChar | -| regexp.cpp:36:19:36:24 | [^A-Z] | RegExpCharacterClass | -| regexp.cpp:36:21:36:21 | A | RegExpConstant,RegExpNormalChar | -| regexp.cpp:36:21:36:23 | A-Z | RegExpCharacterRange | -| regexp.cpp:36:23:36:23 | Z | RegExpConstant,RegExpNormalChar | -| regexp.cpp:37:19:37:21 | []] | RegExpCharacterClass | -| regexp.cpp:37:20:37:20 | ] | RegExpConstant,RegExpNormalChar | -| regexp.cpp:38:19:38:22 | [^]] | RegExpCharacterClass | -| regexp.cpp:38:21:38:21 | ] | RegExpConstant,RegExpNormalChar | -| regexp.cpp:39:19:39:22 | [^-] | RegExpCharacterClass | -| regexp.cpp:39:21:39:21 | - | RegExpConstant,RegExpNormalChar | -| regexp.cpp:40:20:40:22 | [\|] | RegExpCharacterClass | -| regexp.cpp:40:21:40:21 | \| | RegExpConstant,RegExpNormalChar | -| regexp.cpp:43:22:43:27 | [[a-f] | RegExpCharacterClass | -| regexp.cpp:43:22:43:31 | [[a-f]A-F] | RegExpSequence | -| regexp.cpp:43:23:43:23 | [ | RegExpConstant,RegExpNormalChar | -| regexp.cpp:43:24:43:24 | a | RegExpConstant,RegExpNormalChar | -| regexp.cpp:43:24:43:26 | a-f | RegExpCharacterRange | -| regexp.cpp:43:26:43:26 | f | RegExpConstant,RegExpNormalChar | -| regexp.cpp:43:28:43:31 | A-F] | RegExpConstant,RegExpNormalChar | -| regexp.cpp:46:21:46:21 | . | RegExpDot | -| regexp.cpp:46:21:46:22 | .* | RegExpStar | -| regexp.cpp:47:22:47:22 | . | RegExpDot | -| regexp.cpp:47:22:47:23 | .* | RegExpStar | -| regexp.cpp:48:21:48:22 | \\w | RegExpCharacterClassEscape | -| regexp.cpp:48:21:48:23 | \\w+ | RegExpPlus | -| regexp.cpp:48:21:48:25 | \\w+\\W | RegExpSequence | -| regexp.cpp:48:24:48:25 | \\W | RegExpCharacterClassEscape | -| regexp.cpp:49:21:49:22 | \\s | RegExpCharacterClassEscape | -| regexp.cpp:49:21:49:24 | \\s\\S | RegExpSequence | -| regexp.cpp:49:23:49:24 | \\S | RegExpCharacterClassEscape | -| regexp.cpp:50:21:50:22 | \\d | RegExpCharacterClassEscape | -| regexp.cpp:50:21:50:24 | \\d\\D | RegExpSequence | -| regexp.cpp:50:23:50:24 | \\D | RegExpCharacterClassEscape | -| regexp.cpp:51:21:51:22 | \\h | RegExpCharacterClassEscape | -| regexp.cpp:51:21:51:24 | \\h\\H | RegExpSequence | -| regexp.cpp:51:23:51:24 | \\H | RegExpCharacterClassEscape | -| regexp.cpp:52:21:52:22 | \\n | RegExpConstant,RegExpEscape | -| regexp.cpp:52:21:52:26 | \\n\\r\\t | RegExpSequence | -| regexp.cpp:52:23:52:24 | \\r | RegExpConstant,RegExpEscape | -| regexp.cpp:52:25:52:26 | \\t | RegExpConstant,RegExpEscape | -| regexp.cpp:55:20:55:21 | \\G | RegExpSpecialChar | -| regexp.cpp:55:20:55:24 | \\Gabc | RegExpSequence | -| regexp.cpp:55:22:55:24 | abc | RegExpConstant,RegExpNormalChar | -| regexp.cpp:56:20:56:21 | \\b | RegExpSpecialChar | -| regexp.cpp:56:20:56:25 | \\b!a\\B | RegExpSequence | -| regexp.cpp:56:22:56:23 | !a | RegExpConstant,RegExpNormalChar | -| regexp.cpp:56:24:56:25 | \\B | RegExpNonWordBoundary | -| regexp.cpp:59:20:59:24 | (foo) | RegExpGroup | -| regexp.cpp:59:20:59:25 | (foo)* | RegExpStar | -| regexp.cpp:59:20:59:28 | (foo)*bar | RegExpSequence | -| regexp.cpp:59:21:59:23 | foo | RegExpConstant,RegExpNormalChar | -| regexp.cpp:59:26:59:28 | bar | RegExpConstant,RegExpNormalChar | -| regexp.cpp:60:20:60:21 | fo | RegExpConstant,RegExpNormalChar | -| regexp.cpp:60:20:60:28 | fo(o\|b)ar | RegExpSequence | -| regexp.cpp:60:22:60:26 | (o\|b) | RegExpGroup | -| regexp.cpp:60:23:60:23 | o | RegExpConstant,RegExpNormalChar | -| regexp.cpp:60:23:60:25 | o\|b | RegExpAlt | -| regexp.cpp:60:25:60:25 | b | RegExpConstant,RegExpNormalChar | -| regexp.cpp:60:27:60:28 | ar | RegExpConstant,RegExpNormalChar | -| regexp.cpp:61:20:61:27 | (a\|b\|cd) | RegExpGroup | -| regexp.cpp:61:20:61:28 | (a\|b\|cd)e | RegExpSequence | -| regexp.cpp:61:21:61:21 | a | RegExpConstant,RegExpNormalChar | -| regexp.cpp:61:21:61:26 | a\|b\|cd | RegExpAlt | -| regexp.cpp:61:23:61:23 | b | RegExpConstant,RegExpNormalChar | -| regexp.cpp:61:25:61:26 | cd | RegExpConstant,RegExpNormalChar | -| regexp.cpp:61:28:61:28 | e | RegExpConstant,RegExpNormalChar | -| regexp.cpp:62:20:62:25 | (?::+) | RegExpGroup | -| regexp.cpp:62:20:62:27 | (?::+)\\w | RegExpSequence | -| regexp.cpp:62:23:62:23 | : | RegExpConstant,RegExpNormalChar | -| regexp.cpp:62:23:62:24 | :+ | RegExpPlus | -| regexp.cpp:62:26:62:27 | \\w | RegExpCharacterClassEscape | -| regexp.cpp:65:19:65:28 | (?\\w+) | RegExpGroup | -| regexp.cpp:65:25:65:26 | \\w | RegExpCharacterClassEscape | -| regexp.cpp:65:25:65:27 | \\w+ | RegExpPlus | -| regexp.cpp:66:19:66:29 | (?'foo'fo+) | RegExpGroup | -| regexp.cpp:66:26:66:26 | f | RegExpConstant,RegExpNormalChar | -| regexp.cpp:66:26:66:28 | fo+ | RegExpSequence | -| regexp.cpp:66:27:66:27 | o | RegExpConstant,RegExpNormalChar | -| regexp.cpp:66:27:66:28 | o+ | RegExpPlus | -| regexp.cpp:69:21:69:24 | (a+) | RegExpGroup | -| regexp.cpp:69:21:69:28 | (a+)b+\\1 | RegExpSequence | -| regexp.cpp:69:22:69:22 | a | RegExpConstant,RegExpNormalChar | -| regexp.cpp:69:22:69:23 | a+ | RegExpPlus | -| regexp.cpp:69:25:69:25 | b | RegExpConstant,RegExpNormalChar | -| regexp.cpp:69:25:69:26 | b+ | RegExpPlus | -| regexp.cpp:69:27:69:28 | \\1 | RegExpBackRef | -| regexp.cpp:70:21:70:30 | (?q+) | RegExpGroup | -| regexp.cpp:70:21:70:41 | (?q+)\\s+\\k+ | RegExpSequence | -| regexp.cpp:70:28:70:28 | q | RegExpConstant,RegExpNormalChar | -| regexp.cpp:70:28:70:29 | q+ | RegExpPlus | -| regexp.cpp:70:31:70:32 | \\s | RegExpCharacterClassEscape | -| regexp.cpp:70:31:70:33 | \\s+ | RegExpPlus | -| regexp.cpp:70:34:70:40 | \\k | RegExpBackRef | -| regexp.cpp:70:34:70:41 | \\k+ | RegExpPlus | -| regexp.cpp:73:21:73:28 | \\p{Word} | RegExpNamedCharacterProperty | -| regexp.cpp:73:21:73:29 | \\p{Word}* | RegExpStar | -| regexp.cpp:74:21:74:29 | \\P{Digit} | RegExpNamedCharacterProperty | -| regexp.cpp:74:21:74:30 | \\P{Digit}+ | RegExpPlus | -| regexp.cpp:75:21:75:30 | \\p{^Alnum} | RegExpNamedCharacterProperty | -| regexp.cpp:75:21:75:35 | \\p{^Alnum}{2,3} | RegExpRange | -| regexp.cpp:76:21:76:34 | [a-f\\p{Digit}] | RegExpCharacterClass | -| regexp.cpp:76:21:76:35 | [a-f\\p{Digit}]+ | RegExpPlus | -| regexp.cpp:76:22:76:22 | a | RegExpConstant,RegExpNormalChar | -| regexp.cpp:76:22:76:24 | a-f | RegExpCharacterRange | -| regexp.cpp:76:24:76:24 | f | RegExpConstant,RegExpNormalChar | -| regexp.cpp:76:25:76:33 | \\p{Digit} | RegExpNamedCharacterProperty | -| regexp.cpp:79:22:79:32 | [[:alpha:]] | RegExpCharacterClass | -| regexp.cpp:79:22:79:43 | [[:alpha:]][[:digit:]] | RegExpSequence | -| regexp.cpp:79:23:79:31 | [:alpha:] | RegExpNamedCharacterProperty | -| regexp.cpp:79:33:79:43 | [[:digit:]] | RegExpCharacterClass | -| regexp.cpp:79:34:79:42 | [:digit:] | RegExpNamedCharacterProperty | -| regexp.cpp:82:22:82:41 | [[:alpha:][:digit:]] | RegExpCharacterClass | -| regexp.cpp:82:23:82:31 | [:alpha:] | RegExpNamedCharacterProperty | -| regexp.cpp:82:32:82:40 | [:digit:] | RegExpNamedCharacterProperty | -| regexp.cpp:85:22:85:38 | [A-F[:digit:]a-f] | RegExpCharacterClass | -| regexp.cpp:85:23:85:23 | A | RegExpConstant,RegExpNormalChar | -| regexp.cpp:85:23:85:25 | A-F | RegExpCharacterRange | -| regexp.cpp:85:25:85:25 | F | RegExpConstant,RegExpNormalChar | -| regexp.cpp:85:26:85:34 | [:digit:] | RegExpNamedCharacterProperty | -| regexp.cpp:85:35:85:35 | a | RegExpConstant,RegExpNormalChar | -| regexp.cpp:85:35:85:37 | a-f | RegExpCharacterRange | -| regexp.cpp:85:37:85:37 | f | RegExpConstant,RegExpNormalChar | -| regexp.cpp:88:22:88:30 | [:digit:] | RegExpNamedCharacterProperty | -| regexp.cpp:91:19:91:24 | \\u{987 | RegExpConstant,RegExpEscape | -| regexp.cpp:94:25:94:25 | a | RegExpConstant,RegExpNormalChar | -| regexp.cpp:94:25:94:28 | a\\nb | RegExpSequence | -| regexp.cpp:94:26:94:27 | \\n | RegExpConstant,RegExpEscape | -| regexp.cpp:94:28:94:28 | b | RegExpConstant,RegExpNormalChar | -| regexp.cpp:95:36:95:38 | abc | RegExpConstant,RegExpNormalChar | -| regexp.cpp:96:34:96:36 | abc | RegExpConstant,RegExpNormalChar | -| regexp.cpp:97:37:97:39 | abc | RegExpConstant,RegExpNormalChar | -| regexp.cpp:98:37:98:39 | abc | RegExpConstant,RegExpNormalChar | -| regexp.cpp:99:21:99:23 | abc | RegExpConstant,RegExpNormalChar | -| regexp.cpp:100:37:100:39 | abc | RegExpConstant,RegExpNormalChar | -| regexp.cpp:101:35:101:37 | abc | RegExpConstant,RegExpNormalChar | -| regexp.cpp:102:38:102:40 | abc | RegExpConstant,RegExpNormalChar | -| regexp.cpp:103:38:103:40 | abc | RegExpConstant,RegExpNormalChar | -| regexp.cpp:104:22:104:24 | abc | RegExpConstant,RegExpNormalChar | -| regexp.cpp:105:24:105:26 | abc | RegExpConstant,RegExpNormalChar | +| file://:0:0:0:0 | 0 | RegExpConstant,RegExpNormalChar | +| file://:0:0:0:0 | 0-9 | RegExpCharacterRange | +| file://:0:0:0:0 | 1 | RegExpConstant,RegExpNormalChar | +| file://:0:0:0:0 | 2 | RegExpConstant,RegExpNormalChar | +| file://:0:0:0:0 | 3 | RegExpConstant,RegExpNormalChar | +| file://:0:0:0:0 | 9 | RegExpConstant,RegExpNormalChar | +| file://:0:0:0:0 | !a | RegExpConstant,RegExpNormalChar | +| file://:0:0:0:0 | (?'foo'fo+) | RegExpGroup | +| file://:0:0:0:0 | (?::+) | RegExpGroup | +| file://:0:0:0:0 | (?::+)\\w | RegExpSequence | +| file://:0:0:0:0 | (?\\w+) | RegExpGroup | +| file://:0:0:0:0 | (?q+) | RegExpGroup | +| file://:0:0:0:0 | (?q+)\\s+\\k+ | RegExpSequence | +| file://:0:0:0:0 | (a+) | RegExpGroup | +| file://:0:0:0:0 | (a+)b+\\1 | RegExpSequence | +| file://:0:0:0:0 | (a\|b\|cd) | RegExpGroup | +| file://:0:0:0:0 | (a\|b\|cd)e | RegExpSequence | +| file://:0:0:0:0 | (foo) | RegExpGroup | +| file://:0:0:0:0 | (foo)* | RegExpStar | +| file://:0:0:0:0 | (foo)*bar | RegExpSequence | +| file://:0:0:0:0 | (o\|b) | RegExpGroup | +| file://:0:0:0:0 | + | RegExpConstant,RegExpNormalChar | +| file://:0:0:0:0 | - | RegExpConstant,RegExpNormalChar | +| file://:0:0:0:0 | - | RegExpConstant,RegExpNormalChar | +| file://:0:0:0:0 | . | RegExpDot | +| file://:0:0:0:0 | . | RegExpDot | +| file://:0:0:0:0 | .* | RegExpStar | +| file://:0:0:0:0 | .* | RegExpStar | +| file://:0:0:0:0 | : | RegExpConstant,RegExpNormalChar | +| file://:0:0:0:0 | :+ | RegExpPlus | +| file://:0:0:0:0 | A | RegExpConstant,RegExpNormalChar | +| file://:0:0:0:0 | A | RegExpConstant,RegExpNormalChar | +| file://:0:0:0:0 | A | RegExpConstant,RegExpNormalChar | +| file://:0:0:0:0 | A-F | RegExpCharacterRange | +| file://:0:0:0:0 | A-F | RegExpCharacterRange | +| file://:0:0:0:0 | A-F] | RegExpConstant,RegExpNormalChar | +| file://:0:0:0:0 | A-Z | RegExpCharacterRange | +| file://:0:0:0:0 | F | RegExpConstant,RegExpNormalChar | +| file://:0:0:0:0 | F | RegExpConstant,RegExpNormalChar | +| file://:0:0:0:0 | Z | RegExpConstant,RegExpNormalChar | +| file://:0:0:0:0 | [ | RegExpConstant,RegExpNormalChar | +| file://:0:0:0:0 | [123] | RegExpCharacterClass | +| file://:0:0:0:0 | [+-] | RegExpCharacterClass | +| file://:0:0:0:0 | [+-]? | RegExpOpt | +| file://:0:0:0:0 | [:alpha:] | RegExpNamedCharacterProperty | +| file://:0:0:0:0 | [:alpha:] | RegExpNamedCharacterProperty | +| file://:0:0:0:0 | [:digit:] | RegExpNamedCharacterProperty | +| file://:0:0:0:0 | [:digit:] | RegExpNamedCharacterProperty | +| file://:0:0:0:0 | [:digit:] | RegExpNamedCharacterProperty | +| file://:0:0:0:0 | [:digit:] | RegExpNamedCharacterProperty | +| file://:0:0:0:0 | [A-F[:digit:]a-f] | RegExpCharacterClass | +| file://:0:0:0:0 | [[:alpha:][:digit:]] | RegExpCharacterClass | +| file://:0:0:0:0 | [[:alpha:]] | RegExpCharacterClass | +| file://:0:0:0:0 | [[:alpha:]][[:digit:]] | RegExpSequence | +| file://:0:0:0:0 | [[:digit:]] | RegExpCharacterClass | +| file://:0:0:0:0 | [[a-f] | RegExpCharacterClass | +| file://:0:0:0:0 | [[a-f]A-F] | RegExpSequence | +| file://:0:0:0:0 | [\\w] | RegExpCharacterClass | +| file://:0:0:0:0 | [\\w]+ | RegExpPlus | +| file://:0:0:0:0 | [\|] | RegExpCharacterClass | +| file://:0:0:0:0 | []] | RegExpCharacterClass | +| file://:0:0:0:0 | [^-] | RegExpCharacterClass | +| file://:0:0:0:0 | [^A-Z] | RegExpCharacterClass | +| file://:0:0:0:0 | [^]] | RegExpCharacterClass | +| file://:0:0:0:0 | [a-fA-F0-9_] | RegExpCharacterClass | +| file://:0:0:0:0 | [a-f\\p{Digit}] | RegExpCharacterClass | +| file://:0:0:0:0 | [a-f\\p{Digit}]+ | RegExpPlus | +| file://:0:0:0:0 | [abc] | RegExpCharacterClass | +| file://:0:0:0:0 | \\1 | RegExpBackRef | +| file://:0:0:0:0 | \\A | RegExpCaret | +| file://:0:0:0:0 | \\A[+-]?\\d+ | RegExpSequence | +| file://:0:0:0:0 | \\B | RegExpNonWordBoundary | +| file://:0:0:0:0 | \\D | RegExpCharacterClassEscape | +| file://:0:0:0:0 | \\G | RegExpSpecialChar | +| file://:0:0:0:0 | \\Gabc | RegExpSequence | +| file://:0:0:0:0 | \\H | RegExpCharacterClassEscape | +| file://:0:0:0:0 | \\P{Digit} | RegExpNamedCharacterProperty | +| file://:0:0:0:0 | \\P{Digit}+ | RegExpPlus | +| file://:0:0:0:0 | \\S | RegExpCharacterClassEscape | +| file://:0:0:0:0 | \\W | RegExpCharacterClassEscape | +| file://:0:0:0:0 | \\[ | RegExpConstant,RegExpEscape | +| file://:0:0:0:0 | \\[\\][123] | RegExpSequence | +| file://:0:0:0:0 | \\] | RegExpConstant,RegExpEscape | +| file://:0:0:0:0 | \\b | RegExpSpecialChar | +| file://:0:0:0:0 | \\b!a\\B | RegExpSequence | +| file://:0:0:0:0 | \\d | RegExpCharacterClassEscape | +| file://:0:0:0:0 | \\d | RegExpCharacterClassEscape | +| file://:0:0:0:0 | \\d+ | RegExpPlus | +| file://:0:0:0:0 | \\d\\D | RegExpSequence | +| file://:0:0:0:0 | \\h | RegExpCharacterClassEscape | +| file://:0:0:0:0 | \\h\\H | RegExpSequence | +| file://:0:0:0:0 | \\k | RegExpBackRef | +| file://:0:0:0:0 | \\k+ | RegExpPlus | +| file://:0:0:0:0 | \\n | RegExpConstant,RegExpEscape | +| file://:0:0:0:0 | \\n | RegExpConstant,RegExpEscape | +| file://:0:0:0:0 | \\n\\r\\t | RegExpSequence | +| file://:0:0:0:0 | \\p{Digit} | RegExpNamedCharacterProperty | +| file://:0:0:0:0 | \\p{Word} | RegExpNamedCharacterProperty | +| file://:0:0:0:0 | \\p{Word}* | RegExpStar | +| file://:0:0:0:0 | \\p{^Alnum} | RegExpNamedCharacterProperty | +| file://:0:0:0:0 | \\p{^Alnum}{2,3} | RegExpRange | +| file://:0:0:0:0 | \\r | RegExpConstant,RegExpEscape | +| file://:0:0:0:0 | \\s | RegExpCharacterClassEscape | +| file://:0:0:0:0 | \\s | RegExpCharacterClassEscape | +| file://:0:0:0:0 | \\s+ | RegExpPlus | +| file://:0:0:0:0 | \\s\\S | RegExpSequence | +| file://:0:0:0:0 | \\t | RegExpConstant,RegExpEscape | +| file://:0:0:0:0 | \\u{987 | RegExpConstant,RegExpEscape | +| file://:0:0:0:0 | \\w | RegExpCharacterClassEscape | +| file://:0:0:0:0 | \\w | RegExpCharacterClassEscape | +| file://:0:0:0:0 | \\w | RegExpCharacterClassEscape | +| file://:0:0:0:0 | \\w | RegExpCharacterClassEscape | +| file://:0:0:0:0 | \\w+ | RegExpPlus | +| file://:0:0:0:0 | \\w+ | RegExpPlus | +| file://:0:0:0:0 | \\w+\\W | RegExpSequence | +| file://:0:0:0:0 | \| | RegExpConstant,RegExpNormalChar | +| file://:0:0:0:0 | ] | RegExpConstant,RegExpNormalChar | +| file://:0:0:0:0 | ] | RegExpConstant,RegExpNormalChar | +| file://:0:0:0:0 | _ | RegExpConstant,RegExpNormalChar | +| file://:0:0:0:0 | a | RegExpConstant,RegExpNormalChar | +| file://:0:0:0:0 | a | RegExpConstant,RegExpNormalChar | +| file://:0:0:0:0 | a | RegExpConstant,RegExpNormalChar | +| file://:0:0:0:0 | a | RegExpConstant,RegExpNormalChar | +| file://:0:0:0:0 | a | RegExpConstant,RegExpNormalChar | +| file://:0:0:0:0 | a | RegExpConstant,RegExpNormalChar | +| file://:0:0:0:0 | a | RegExpConstant,RegExpNormalChar | +| file://:0:0:0:0 | a | RegExpConstant,RegExpNormalChar | +| file://:0:0:0:0 | a | RegExpConstant,RegExpNormalChar | +| file://:0:0:0:0 | a | RegExpConstant,RegExpNormalChar | +| file://:0:0:0:0 | a | RegExpConstant,RegExpNormalChar | +| file://:0:0:0:0 | a | RegExpConstant,RegExpNormalChar | +| file://:0:0:0:0 | a | RegExpConstant,RegExpNormalChar | +| file://:0:0:0:0 | a* | RegExpStar | +| file://:0:0:0:0 | a*b+c?d | RegExpSequence | +| file://:0:0:0:0 | a+ | RegExpPlus | +| file://:0:0:0:0 | a-f | RegExpCharacterRange | +| file://:0:0:0:0 | a-f | RegExpCharacterRange | +| file://:0:0:0:0 | a-f | RegExpCharacterRange | +| file://:0:0:0:0 | a-f | RegExpCharacterRange | +| file://:0:0:0:0 | a\\nb | RegExpSequence | +| file://:0:0:0:0 | a\|b\|cd | RegExpAlt | +| file://:0:0:0:0 | abc | RegExpConstant,RegExpNormalChar | +| file://:0:0:0:0 | abc | RegExpConstant,RegExpNormalChar | +| file://:0:0:0:0 | abc | RegExpConstant,RegExpNormalChar | +| file://:0:0:0:0 | abc | RegExpConstant,RegExpNormalChar | +| file://:0:0:0:0 | abc | RegExpConstant,RegExpNormalChar | +| file://:0:0:0:0 | abc | RegExpConstant,RegExpNormalChar | +| file://:0:0:0:0 | abc | RegExpConstant,RegExpNormalChar | +| file://:0:0:0:0 | abc | RegExpConstant,RegExpNormalChar | +| file://:0:0:0:0 | abc | RegExpConstant,RegExpNormalChar | +| file://:0:0:0:0 | abc | RegExpConstant,RegExpNormalChar | +| file://:0:0:0:0 | abc | RegExpConstant,RegExpNormalChar | +| file://:0:0:0:0 | abc | RegExpConstant,RegExpNormalChar | +| file://:0:0:0:0 | abc | RegExpConstant,RegExpNormalChar | +| file://:0:0:0:0 | ar | RegExpConstant,RegExpNormalChar | +| file://:0:0:0:0 | a{3,} | InfiniteRepetitionQuantifier,RegExpRange | +| file://:0:0:0:0 | a{4,8} | RegExpRange | +| file://:0:0:0:0 | a{7} | RegExpRange | +| file://:0:0:0:0 | a{,8} | RegExpRange | +| file://:0:0:0:0 | b | RegExpConstant,RegExpNormalChar | +| file://:0:0:0:0 | b | RegExpConstant,RegExpNormalChar | +| file://:0:0:0:0 | b | RegExpConstant,RegExpNormalChar | +| file://:0:0:0:0 | b | RegExpConstant,RegExpNormalChar | +| file://:0:0:0:0 | b | RegExpConstant,RegExpNormalChar | +| file://:0:0:0:0 | b | RegExpConstant,RegExpNormalChar | +| file://:0:0:0:0 | b+ | RegExpPlus | +| file://:0:0:0:0 | b+ | RegExpPlus | +| file://:0:0:0:0 | bar | RegExpConstant,RegExpNormalChar | +| file://:0:0:0:0 | bar | RegExpConstant,RegExpNormalChar | +| file://:0:0:0:0 | c | RegExpConstant,RegExpNormalChar | +| file://:0:0:0:0 | c | RegExpConstant,RegExpNormalChar | +| file://:0:0:0:0 | c? | RegExpOpt | +| file://:0:0:0:0 | cd | RegExpConstant,RegExpNormalChar | +| file://:0:0:0:0 | d | RegExpConstant,RegExpNormalChar | +| file://:0:0:0:0 | e | RegExpConstant,RegExpNormalChar | +| file://:0:0:0:0 | f | RegExpConstant,RegExpNormalChar | +| file://:0:0:0:0 | f | RegExpConstant,RegExpNormalChar | +| file://:0:0:0:0 | f | RegExpConstant,RegExpNormalChar | +| file://:0:0:0:0 | f | RegExpConstant,RegExpNormalChar | +| file://:0:0:0:0 | f | RegExpConstant,RegExpNormalChar | +| file://:0:0:0:0 | fo | RegExpConstant,RegExpNormalChar | +| file://:0:0:0:0 | fo(o\|b)ar | RegExpSequence | +| file://:0:0:0:0 | fo+ | RegExpSequence | +| file://:0:0:0:0 | foo | RegExpConstant,RegExpNormalChar | +| file://:0:0:0:0 | foo | RegExpConstant,RegExpNormalChar | +| file://:0:0:0:0 | foo\|bar | RegExpAlt | +| file://:0:0:0:0 | o | RegExpConstant,RegExpNormalChar | +| file://:0:0:0:0 | o | RegExpConstant,RegExpNormalChar | +| file://:0:0:0:0 | o+ | RegExpPlus | +| file://:0:0:0:0 | o\|b | RegExpAlt | +| file://:0:0:0:0 | q | RegExpConstant,RegExpNormalChar | +| file://:0:0:0:0 | q+ | RegExpPlus | regExpNormalCharValue -| regexp.cpp:18:19:18:21 | abc | abc | -| regexp.cpp:21:20:21:20 | a | a | -| regexp.cpp:21:22:21:22 | b | b | -| regexp.cpp:21:24:21:24 | c | c | -| regexp.cpp:21:26:21:26 | d | d | -| regexp.cpp:22:20:22:20 | a | a | -| regexp.cpp:23:20:23:20 | a | a | -| regexp.cpp:24:20:24:20 | a | a | -| regexp.cpp:25:20:25:20 | a | a | -| regexp.cpp:28:19:28:21 | foo | foo | -| regexp.cpp:28:23:28:25 | bar | bar | -| regexp.cpp:31:20:31:20 | a | a | -| regexp.cpp:31:21:31:21 | b | b | -| regexp.cpp:31:22:31:22 | c | c | -| regexp.cpp:32:20:32:20 | a | a | -| regexp.cpp:32:22:32:22 | f | f | -| regexp.cpp:32:23:32:23 | A | A | -| regexp.cpp:32:25:32:25 | F | F | -| regexp.cpp:32:26:32:26 | 0 | 0 | -| regexp.cpp:32:28:32:28 | 9 | 9 | -| regexp.cpp:32:29:32:29 | _ | _ | -| regexp.cpp:33:22:33:22 | + | + | -| regexp.cpp:33:23:33:23 | - | - | -| regexp.cpp:33:26:33:27 | \\d | d | -| regexp.cpp:34:20:34:21 | \\w | w | -| regexp.cpp:35:19:35:20 | \\[ | [ | -| regexp.cpp:35:21:35:22 | \\] | ] | -| regexp.cpp:35:24:35:24 | 1 | 1 | -| regexp.cpp:35:25:35:25 | 2 | 2 | -| regexp.cpp:35:26:35:26 | 3 | 3 | -| regexp.cpp:36:21:36:21 | A | A | -| regexp.cpp:36:23:36:23 | Z | Z | -| regexp.cpp:37:20:37:20 | ] | ] | -| regexp.cpp:38:21:38:21 | ] | ] | -| regexp.cpp:39:21:39:21 | - | - | -| regexp.cpp:40:21:40:21 | \| | \| | -| regexp.cpp:43:23:43:23 | [ | [ | -| regexp.cpp:43:24:43:24 | a | a | -| regexp.cpp:43:26:43:26 | f | f | -| regexp.cpp:43:28:43:31 | A-F] | A-F] | -| regexp.cpp:48:21:48:22 | \\w | w | -| regexp.cpp:48:24:48:25 | \\W | W | -| regexp.cpp:49:21:49:22 | \\s | s | -| regexp.cpp:49:23:49:24 | \\S | S | -| regexp.cpp:50:21:50:22 | \\d | d | -| regexp.cpp:50:23:50:24 | \\D | D | -| regexp.cpp:51:21:51:22 | \\h | h | -| regexp.cpp:51:23:51:24 | \\H | H | -| regexp.cpp:52:21:52:22 | \\n | \n | -| regexp.cpp:52:23:52:24 | \\r | \r | -| regexp.cpp:52:25:52:26 | \\t | \t | -| regexp.cpp:55:22:55:24 | abc | abc | -| regexp.cpp:56:22:56:23 | !a | !a | -| regexp.cpp:59:21:59:23 | foo | foo | -| regexp.cpp:59:26:59:28 | bar | bar | -| regexp.cpp:60:20:60:21 | fo | fo | -| regexp.cpp:60:23:60:23 | o | o | -| regexp.cpp:60:25:60:25 | b | b | -| regexp.cpp:60:27:60:28 | ar | ar | -| regexp.cpp:61:21:61:21 | a | a | -| regexp.cpp:61:23:61:23 | b | b | -| regexp.cpp:61:25:61:26 | cd | cd | -| regexp.cpp:61:28:61:28 | e | e | -| regexp.cpp:62:23:62:23 | : | : | -| regexp.cpp:62:26:62:27 | \\w | w | -| regexp.cpp:65:25:65:26 | \\w | w | -| regexp.cpp:66:26:66:26 | f | f | -| regexp.cpp:66:27:66:27 | o | o | -| regexp.cpp:69:22:69:22 | a | a | -| regexp.cpp:69:25:69:25 | b | b | -| regexp.cpp:70:28:70:28 | q | q | -| regexp.cpp:70:31:70:32 | \\s | s | -| regexp.cpp:76:22:76:22 | a | a | -| regexp.cpp:76:24:76:24 | f | f | -| regexp.cpp:85:23:85:23 | A | A | -| regexp.cpp:85:25:85:25 | F | F | -| regexp.cpp:85:35:85:35 | a | a | -| regexp.cpp:85:37:85:37 | f | f | -| regexp.cpp:91:19:91:24 | \\u{987 | \u0987 | -| regexp.cpp:94:25:94:25 | a | a | -| regexp.cpp:94:26:94:27 | \\n | \n | -| regexp.cpp:94:28:94:28 | b | b | -| regexp.cpp:95:36:95:38 | abc | abc | -| regexp.cpp:96:34:96:36 | abc | abc | -| regexp.cpp:97:37:97:39 | abc | abc | -| regexp.cpp:98:37:98:39 | abc | abc | -| regexp.cpp:99:21:99:23 | abc | abc | -| regexp.cpp:100:37:100:39 | abc | abc | -| regexp.cpp:101:35:101:37 | abc | abc | -| regexp.cpp:102:38:102:40 | abc | abc | -| regexp.cpp:103:38:103:40 | abc | abc | -| regexp.cpp:104:22:104:24 | abc | abc | -| regexp.cpp:105:24:105:26 | abc | abc | +| file://:0:0:0:0 | 0 | 0 | +| file://:0:0:0:0 | 1 | 1 | +| file://:0:0:0:0 | 2 | 2 | +| file://:0:0:0:0 | 3 | 3 | +| file://:0:0:0:0 | 9 | 9 | +| file://:0:0:0:0 | !a | !a | +| file://:0:0:0:0 | + | + | +| file://:0:0:0:0 | - | - | +| file://:0:0:0:0 | - | - | +| file://:0:0:0:0 | : | : | +| file://:0:0:0:0 | A | A | +| file://:0:0:0:0 | A | A | +| file://:0:0:0:0 | A | A | +| file://:0:0:0:0 | A-F] | A-F] | +| file://:0:0:0:0 | F | F | +| file://:0:0:0:0 | F | F | +| file://:0:0:0:0 | Z | Z | +| file://:0:0:0:0 | [ | [ | +| file://:0:0:0:0 | \\D | D | +| file://:0:0:0:0 | \\H | H | +| file://:0:0:0:0 | \\S | S | +| file://:0:0:0:0 | \\W | W | +| file://:0:0:0:0 | \\[ | [ | +| file://:0:0:0:0 | \\] | ] | +| file://:0:0:0:0 | \\d | d | +| file://:0:0:0:0 | \\d | d | +| file://:0:0:0:0 | \\h | h | +| file://:0:0:0:0 | \\n | \n | +| file://:0:0:0:0 | \\n | \n | +| file://:0:0:0:0 | \\r | \r | +| file://:0:0:0:0 | \\s | s | +| file://:0:0:0:0 | \\s | s | +| file://:0:0:0:0 | \\t | \t | +| file://:0:0:0:0 | \\u{987 | \u0987 | +| file://:0:0:0:0 | \\w | w | +| file://:0:0:0:0 | \\w | w | +| file://:0:0:0:0 | \\w | w | +| file://:0:0:0:0 | \\w | w | +| file://:0:0:0:0 | \| | \| | +| file://:0:0:0:0 | ] | ] | +| file://:0:0:0:0 | ] | ] | +| file://:0:0:0:0 | _ | _ | +| file://:0:0:0:0 | a | a | +| file://:0:0:0:0 | a | a | +| file://:0:0:0:0 | a | a | +| file://:0:0:0:0 | a | a | +| file://:0:0:0:0 | a | a | +| file://:0:0:0:0 | a | a | +| file://:0:0:0:0 | a | a | +| file://:0:0:0:0 | a | a | +| file://:0:0:0:0 | a | a | +| file://:0:0:0:0 | a | a | +| file://:0:0:0:0 | a | a | +| file://:0:0:0:0 | a | a | +| file://:0:0:0:0 | a | a | +| file://:0:0:0:0 | abc | abc | +| file://:0:0:0:0 | abc | abc | +| file://:0:0:0:0 | abc | abc | +| file://:0:0:0:0 | abc | abc | +| file://:0:0:0:0 | abc | abc | +| file://:0:0:0:0 | abc | abc | +| file://:0:0:0:0 | abc | abc | +| file://:0:0:0:0 | abc | abc | +| file://:0:0:0:0 | abc | abc | +| file://:0:0:0:0 | abc | abc | +| file://:0:0:0:0 | abc | abc | +| file://:0:0:0:0 | abc | abc | +| file://:0:0:0:0 | abc | abc | +| file://:0:0:0:0 | ar | ar | +| file://:0:0:0:0 | b | b | +| file://:0:0:0:0 | b | b | +| file://:0:0:0:0 | b | b | +| file://:0:0:0:0 | b | b | +| file://:0:0:0:0 | b | b | +| file://:0:0:0:0 | b | b | +| file://:0:0:0:0 | bar | bar | +| file://:0:0:0:0 | bar | bar | +| file://:0:0:0:0 | c | c | +| file://:0:0:0:0 | c | c | +| file://:0:0:0:0 | cd | cd | +| file://:0:0:0:0 | d | d | +| file://:0:0:0:0 | e | e | +| file://:0:0:0:0 | f | f | +| file://:0:0:0:0 | f | f | +| file://:0:0:0:0 | f | f | +| file://:0:0:0:0 | f | f | +| file://:0:0:0:0 | f | f | +| file://:0:0:0:0 | fo | fo | +| file://:0:0:0:0 | foo | foo | +| file://:0:0:0:0 | foo | foo | +| file://:0:0:0:0 | o | o | +| file://:0:0:0:0 | o | o | +| file://:0:0:0:0 | q | q | From f75d66dc9102f4ea9122a96cf5130f2733428021 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 23 Jul 2026 10:04:43 +0000 Subject: [PATCH 07/26] C++: Remove Ruby-only \A/\Z/\z/\G anchors from regex grammar --- .../semmle/code/cpp/regex/RegexTreeView.qll | 12 +++---- .../code/cpp/regex/internal/ParseRegExp.qll | 10 +++--- .../test/library-tests/regex/parse.expected | 31 ------------------- cpp/ql/test/library-tests/regex/regexp.cpp | 2 -- .../test/library-tests/regex/regexp.expected | 15 --------- 5 files changed, 11 insertions(+), 59 deletions(-) diff --git a/cpp/ql/lib/semmle/code/cpp/regex/RegexTreeView.qll b/cpp/ql/lib/semmle/code/cpp/regex/RegexTreeView.qll index c91b588e51a0..1d961d3b9770 100644 --- a/cpp/ql/lib/semmle/code/cpp/regex/RegexTreeView.qll +++ b/cpp/ql/lib/semmle/code/cpp/regex/RegexTreeView.qll @@ -936,17 +936,17 @@ private module Impl implements RegexTreeViewSig { * Example: * * ``` - * \A + * ^ * ``` */ class RegExpAnchor extends RegExpSpecialChar { - RegExpAnchor() { this.getChar() = ["^", "$", "\\A", "\\Z", "\\z"] } + RegExpAnchor() { this.getChar() = ["^", "$"] } override string getAPrimaryQlClass() { result = "RegExpAnchor" } } /** - * A dollar assertion `$` or `\Z` matching the end of a line. + * A dollar assertion `$` matching the end of a line. * * Example: * @@ -955,7 +955,7 @@ private module Impl implements RegexTreeViewSig { * ``` */ class RegExpDollar extends RegExpAnchor { - RegExpDollar() { this.getChar() = ["$", "\\Z", "\\z"] } + RegExpDollar() { this.getChar() = "$" } override string getAPrimaryQlClass() { result = "RegExpDollar" } @@ -963,7 +963,7 @@ private module Impl implements RegexTreeViewSig { } /** - * A caret assertion `^` or `\A` matching the beginning of a line. + * A caret assertion `^` matching the beginning of a line. * * Example: * @@ -972,7 +972,7 @@ private module Impl implements RegexTreeViewSig { * ``` */ class RegExpCaret extends RegExpAnchor { - RegExpCaret() { this.getChar() = ["^", "\\A"] } + RegExpCaret() { this.getChar() = "^" } override string getAPrimaryQlClass() { result = "RegExpCaret" } diff --git a/cpp/ql/lib/semmle/code/cpp/regex/internal/ParseRegExp.qll b/cpp/ql/lib/semmle/code/cpp/regex/internal/ParseRegExp.qll index d9163bb3af05..a7d0d38919a1 100644 --- a/cpp/ql/lib/semmle/code/cpp/regex/internal/ParseRegExp.qll +++ b/cpp/ql/lib/semmle/code/cpp/regex/internal/ParseRegExp.qll @@ -476,7 +476,7 @@ abstract class RegExp extends StringLiteral { end = start + 2 and this.escapingChar(start) and char = this.getText().substring(start, end) and - char = ["\\A", "\\Z", "\\z", "\\G", "\\b", "\\B"] + char = ["\\b", "\\B"] ) } @@ -958,8 +958,8 @@ abstract class RegExp extends StringLiteral { or this.qualifiedItem(x, start, true, _) or - // ^ and \A match the start of the string - this.specialCharacter(x, start, ["^", "\\A"]) + // ^ matches the start of the string + this.specialCharacter(x, start, "^") ) or exists(int y | this.firstPart(start, y) | @@ -984,8 +984,8 @@ abstract class RegExp extends StringLiteral { or this.qualifiedItem(end, y, true, _) or - // $, \Z, and \z match the end of the string. - this.specialCharacter(end, y, ["$", "\\Z", "\\z"]) + // $ matches the end of the string. + this.specialCharacter(end, y, "$") ) or this.lastPart(_, end) and diff --git a/cpp/ql/test/library-tests/regex/parse.expected b/cpp/ql/test/library-tests/regex/parse.expected index 1f92debd8e5c..6eba9076ae45 100644 --- a/cpp/ql/test/library-tests/regex/parse.expected +++ b/cpp/ql/test/library-tests/regex/parse.expected @@ -80,8 +80,6 @@ #-----| [RegExpConstant, RegExpNormalChar] !a -#-----| [RegExpConstant, RegExpNormalChar] abc - #-----| [RegExpConstant, RegExpEscape] \n #-----| [RegExpConstant, RegExpEscape] \r @@ -136,12 +134,6 @@ #-----| [RegExpCharacterClassEscape] \w -#-----| [RegExpConstant, RegExpNormalChar] + - -#-----| [RegExpConstant, RegExpNormalChar] - - -#-----| [RegExpCharacterClassEscape] \d - #-----| [RegExpConstant, RegExpNormalChar] a #-----| [RegExpConstant, RegExpNormalChar] f @@ -229,10 +221,6 @@ #-----| 1 -> [RegExpConstant, RegExpNormalChar] !a #-----| 2 -> [RegExpNonWordBoundary] \B -#-----| [RegExpSequence] \Gabc -#-----| 0 -> [RegExpSpecialChar] \G -#-----| 1 -> [RegExpConstant, RegExpNormalChar] abc - #-----| [RegExpSequence] \n\r\t #-----| 0 -> [RegExpConstant, RegExpEscape] \n #-----| 1 -> [RegExpConstant, RegExpEscape] \r @@ -263,11 +251,6 @@ #-----| 1 -> [RegExpConstant, RegExpEscape] \] #-----| 2 -> [RegExpCharacterClass] [123] -#-----| [RegExpSequence] \A[+-]?\d+ -#-----| 0 -> [RegExpCaret] \A -#-----| 1 -> [RegExpOpt] [+-]? -#-----| 2 -> [RegExpPlus] \d+ - #-----| [RegExpSequence] a*b+c?d #-----| 0 -> [RegExpStar] a* #-----| 1 -> [RegExpPlus] b+ @@ -302,14 +285,10 @@ #-----| [RegExpNonWordBoundary] \B -#-----| [RegExpSpecialChar] \G - #-----| [RegExpDot] . #-----| [RegExpDot] . -#-----| [RegExpCaret] \A - #-----| [RegExpGroup] (?q+) #-----| 0 -> [RegExpPlus] q+ @@ -412,10 +391,6 @@ #-----| [RegExpCharacterClass] [\w] #-----| 0 -> [RegExpCharacterClassEscape] \w -#-----| [RegExpCharacterClass] [+-] -#-----| 0 -> [RegExpConstant, RegExpNormalChar] + -#-----| 1 -> [RegExpConstant, RegExpNormalChar] - - #-----| [RegExpCharacterClass] [a-fA-F0-9_] #-----| 0 -> [RegExpCharacterRange] a-f #-----| 1 -> [RegExpCharacterRange] A-F @@ -491,12 +466,6 @@ #-----| [RegExpPlus] [\w]+ #-----| 0 -> [RegExpCharacterClass] [\w] -#-----| [RegExpOpt] [+-]? -#-----| 0 -> [RegExpCharacterClass] [+-] - -#-----| [RegExpPlus] \d+ -#-----| 0 -> [RegExpCharacterClassEscape] \d - #-----| [RegExpRange] a{7} #-----| 0 -> [RegExpConstant, RegExpNormalChar] a diff --git a/cpp/ql/test/library-tests/regex/regexp.cpp b/cpp/ql/test/library-tests/regex/regexp.cpp index 63bb73d32445..e323213ef23a 100644 --- a/cpp/ql/test/library-tests/regex/regexp.cpp +++ b/cpp/ql/test/library-tests/regex/regexp.cpp @@ -30,7 +30,6 @@ std::regex r_alt("foo|bar"); // Character classes std::regex r_cc1("[abc]"); std::regex r_cc2("[a-fA-F0-9_]"); -std::regex r_cc3("\\A[+-]?\\d+"); std::regex r_cc4("[\\w]+"); std::regex r_cc5("\\[\\][123]"); std::regex r_cc6("[^A-Z]"); @@ -52,7 +51,6 @@ std::regex r_meta5("\\h\\H"); std::regex r_meta6("\\n\\r\\t"); // Anchors -std::regex r_anc1("\\Gabc"); std::regex r_anc2("\\b!a\\B"); // Groups diff --git a/cpp/ql/test/library-tests/regex/regexp.expected b/cpp/ql/test/library-tests/regex/regexp.expected index e671353d19ff..31168fbae14b 100644 --- a/cpp/ql/test/library-tests/regex/regexp.expected +++ b/cpp/ql/test/library-tests/regex/regexp.expected @@ -30,8 +30,6 @@ term | file://:0:0:0:0 | (foo)* | RegExpStar | | file://:0:0:0:0 | (foo)*bar | RegExpSequence | | file://:0:0:0:0 | (o\|b) | RegExpGroup | -| file://:0:0:0:0 | + | RegExpConstant,RegExpNormalChar | -| file://:0:0:0:0 | - | RegExpConstant,RegExpNormalChar | | file://:0:0:0:0 | - | RegExpConstant,RegExpNormalChar | | file://:0:0:0:0 | . | RegExpDot | | file://:0:0:0:0 | . | RegExpDot | @@ -51,8 +49,6 @@ term | file://:0:0:0:0 | Z | RegExpConstant,RegExpNormalChar | | file://:0:0:0:0 | [ | RegExpConstant,RegExpNormalChar | | file://:0:0:0:0 | [123] | RegExpCharacterClass | -| file://:0:0:0:0 | [+-] | RegExpCharacterClass | -| file://:0:0:0:0 | [+-]? | RegExpOpt | | file://:0:0:0:0 | [:alpha:] | RegExpNamedCharacterProperty | | file://:0:0:0:0 | [:alpha:] | RegExpNamedCharacterProperty | | file://:0:0:0:0 | [:digit:] | RegExpNamedCharacterProperty | @@ -78,12 +74,8 @@ term | file://:0:0:0:0 | [a-f\\p{Digit}]+ | RegExpPlus | | file://:0:0:0:0 | [abc] | RegExpCharacterClass | | file://:0:0:0:0 | \\1 | RegExpBackRef | -| file://:0:0:0:0 | \\A | RegExpCaret | -| file://:0:0:0:0 | \\A[+-]?\\d+ | RegExpSequence | | file://:0:0:0:0 | \\B | RegExpNonWordBoundary | | file://:0:0:0:0 | \\D | RegExpCharacterClassEscape | -| file://:0:0:0:0 | \\G | RegExpSpecialChar | -| file://:0:0:0:0 | \\Gabc | RegExpSequence | | file://:0:0:0:0 | \\H | RegExpCharacterClassEscape | | file://:0:0:0:0 | \\P{Digit} | RegExpNamedCharacterProperty | | file://:0:0:0:0 | \\P{Digit}+ | RegExpPlus | @@ -95,8 +87,6 @@ term | file://:0:0:0:0 | \\b | RegExpSpecialChar | | file://:0:0:0:0 | \\b!a\\B | RegExpSequence | | file://:0:0:0:0 | \\d | RegExpCharacterClassEscape | -| file://:0:0:0:0 | \\d | RegExpCharacterClassEscape | -| file://:0:0:0:0 | \\d+ | RegExpPlus | | file://:0:0:0:0 | \\d\\D | RegExpSequence | | file://:0:0:0:0 | \\h | RegExpCharacterClassEscape | | file://:0:0:0:0 | \\h\\H | RegExpSequence | @@ -162,7 +152,6 @@ term | file://:0:0:0:0 | abc | RegExpConstant,RegExpNormalChar | | file://:0:0:0:0 | abc | RegExpConstant,RegExpNormalChar | | file://:0:0:0:0 | abc | RegExpConstant,RegExpNormalChar | -| file://:0:0:0:0 | abc | RegExpConstant,RegExpNormalChar | | file://:0:0:0:0 | ar | RegExpConstant,RegExpNormalChar | | file://:0:0:0:0 | a{3,} | InfiniteRepetitionQuantifier,RegExpRange | | file://:0:0:0:0 | a{4,8} | RegExpRange | @@ -208,8 +197,6 @@ regExpNormalCharValue | file://:0:0:0:0 | 3 | 3 | | file://:0:0:0:0 | 9 | 9 | | file://:0:0:0:0 | !a | !a | -| file://:0:0:0:0 | + | + | -| file://:0:0:0:0 | - | - | | file://:0:0:0:0 | - | - | | file://:0:0:0:0 | : | : | | file://:0:0:0:0 | A | A | @@ -227,7 +214,6 @@ regExpNormalCharValue | file://:0:0:0:0 | \\[ | [ | | file://:0:0:0:0 | \\] | ] | | file://:0:0:0:0 | \\d | d | -| file://:0:0:0:0 | \\d | d | | file://:0:0:0:0 | \\h | h | | file://:0:0:0:0 | \\n | \n | | file://:0:0:0:0 | \\n | \n | @@ -269,7 +255,6 @@ regExpNormalCharValue | file://:0:0:0:0 | abc | abc | | file://:0:0:0:0 | abc | abc | | file://:0:0:0:0 | abc | abc | -| file://:0:0:0:0 | abc | abc | | file://:0:0:0:0 | ar | ar | | file://:0:0:0:0 | b | b | | file://:0:0:0:0 | b | b | From 72bc7170ffa2d44e8dc9747ba101cf0d9a910a60 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 23 Jul 2026 10:06:02 +0000 Subject: [PATCH 08/26] C++: Remove Ruby-only \h and \H character class escapes --- cpp/ql/lib/semmle/code/cpp/regex/RegexTreeView.qll | 2 +- cpp/ql/test/library-tests/regex/parse.expected | 8 -------- cpp/ql/test/library-tests/regex/regexp.cpp | 1 - cpp/ql/test/library-tests/regex/regexp.expected | 5 ----- 4 files changed, 1 insertion(+), 15 deletions(-) diff --git a/cpp/ql/lib/semmle/code/cpp/regex/RegexTreeView.qll b/cpp/ql/lib/semmle/code/cpp/regex/RegexTreeView.qll index 1d961d3b9770..85f26326d287 100644 --- a/cpp/ql/lib/semmle/code/cpp/regex/RegexTreeView.qll +++ b/cpp/ql/lib/semmle/code/cpp/regex/RegexTreeView.qll @@ -651,7 +651,7 @@ private module Impl implements RegexTreeViewSig { * ``` */ class RegExpCharacterClassEscape extends RegExpEscape { - RegExpCharacterClassEscape() { this.getValue() in ["d", "D", "s", "S", "w", "W", "h", "H"] } + RegExpCharacterClassEscape() { this.getValue() in ["d", "D", "s", "S", "w", "W"] } override RegExpTerm getChild(int i) { none() } diff --git a/cpp/ql/test/library-tests/regex/parse.expected b/cpp/ql/test/library-tests/regex/parse.expected index 6eba9076ae45..a01d9f6a61e5 100644 --- a/cpp/ql/test/library-tests/regex/parse.expected +++ b/cpp/ql/test/library-tests/regex/parse.expected @@ -86,10 +86,6 @@ #-----| [RegExpConstant, RegExpEscape] \t -#-----| [RegExpCharacterClassEscape] \h - -#-----| [RegExpCharacterClassEscape] \H - #-----| [RegExpCharacterClassEscape] \d #-----| [RegExpCharacterClassEscape] \D @@ -226,10 +222,6 @@ #-----| 1 -> [RegExpConstant, RegExpEscape] \r #-----| 2 -> [RegExpConstant, RegExpEscape] \t -#-----| [RegExpSequence] \h\H -#-----| 0 -> [RegExpCharacterClassEscape] \h -#-----| 1 -> [RegExpCharacterClassEscape] \H - #-----| [RegExpSequence] \d\D #-----| 0 -> [RegExpCharacterClassEscape] \d #-----| 1 -> [RegExpCharacterClassEscape] \D diff --git a/cpp/ql/test/library-tests/regex/regexp.cpp b/cpp/ql/test/library-tests/regex/regexp.cpp index e323213ef23a..4dc78d789f3b 100644 --- a/cpp/ql/test/library-tests/regex/regexp.cpp +++ b/cpp/ql/test/library-tests/regex/regexp.cpp @@ -47,7 +47,6 @@ std::regex r_meta1m(".*"); // /.*/m mode variant — mode flags are constructor std::regex r_meta2("\\w+\\W"); std::regex r_meta3("\\s\\S"); std::regex r_meta4("\\d\\D"); -std::regex r_meta5("\\h\\H"); std::regex r_meta6("\\n\\r\\t"); // Anchors diff --git a/cpp/ql/test/library-tests/regex/regexp.expected b/cpp/ql/test/library-tests/regex/regexp.expected index 31168fbae14b..770d2f201dd8 100644 --- a/cpp/ql/test/library-tests/regex/regexp.expected +++ b/cpp/ql/test/library-tests/regex/regexp.expected @@ -76,7 +76,6 @@ term | file://:0:0:0:0 | \\1 | RegExpBackRef | | file://:0:0:0:0 | \\B | RegExpNonWordBoundary | | file://:0:0:0:0 | \\D | RegExpCharacterClassEscape | -| file://:0:0:0:0 | \\H | RegExpCharacterClassEscape | | file://:0:0:0:0 | \\P{Digit} | RegExpNamedCharacterProperty | | file://:0:0:0:0 | \\P{Digit}+ | RegExpPlus | | file://:0:0:0:0 | \\S | RegExpCharacterClassEscape | @@ -88,8 +87,6 @@ term | file://:0:0:0:0 | \\b!a\\B | RegExpSequence | | file://:0:0:0:0 | \\d | RegExpCharacterClassEscape | | file://:0:0:0:0 | \\d\\D | RegExpSequence | -| file://:0:0:0:0 | \\h | RegExpCharacterClassEscape | -| file://:0:0:0:0 | \\h\\H | RegExpSequence | | file://:0:0:0:0 | \\k | RegExpBackRef | | file://:0:0:0:0 | \\k+ | RegExpPlus | | file://:0:0:0:0 | \\n | RegExpConstant,RegExpEscape | @@ -208,13 +205,11 @@ regExpNormalCharValue | file://:0:0:0:0 | Z | Z | | file://:0:0:0:0 | [ | [ | | file://:0:0:0:0 | \\D | D | -| file://:0:0:0:0 | \\H | H | | file://:0:0:0:0 | \\S | S | | file://:0:0:0:0 | \\W | W | | file://:0:0:0:0 | \\[ | [ | | file://:0:0:0:0 | \\] | ] | | file://:0:0:0:0 | \\d | d | -| file://:0:0:0:0 | \\h | h | | file://:0:0:0:0 | \\n | \n | | file://:0:0:0:0 | \\n | \n | | file://:0:0:0:0 | \\r | \r | From 1a0b4cd646ffad9a3ba11387c117eb9343982d1d Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 23 Jul 2026 10:07:51 +0000 Subject: [PATCH 09/26] C++: Remove Ruby-style \p and \P named character properties --- .../semmle/code/cpp/regex/RegexTreeView.qll | 46 +---------------- .../code/cpp/regex/internal/ParseRegExp.qll | 41 +-------------- .../test/library-tests/regex/parse.expected | 50 ------------------- cpp/ql/test/library-tests/regex/regexp.cpp | 6 --- .../test/library-tests/regex/regexp.expected | 20 -------- 5 files changed, 2 insertions(+), 161 deletions(-) diff --git a/cpp/ql/lib/semmle/code/cpp/regex/RegexTreeView.qll b/cpp/ql/lib/semmle/code/cpp/regex/RegexTreeView.qll index 85f26326d287..939038dd7227 100644 --- a/cpp/ql/lib/semmle/code/cpp/regex/RegexTreeView.qll +++ b/cpp/ql/lib/semmle/code/cpp/regex/RegexTreeView.qll @@ -49,11 +49,7 @@ private newtype TRegExpParent = not re.specialCharacter(start, end, _) } or /** A back reference */ - TRegExpBackRef(RegExp re, int start, int end) { re.backreference(start, end) } or - /** A named character property */ - TRegExpNamedCharacterProperty(RegExp re, int start, int end) { - re.namedCharacterProperty(start, end, _) - } + TRegExpBackRef(RegExp re, int start, int end) { re.backreference(start, end) } /** An implementation that satisfies the RegexTreeView signature. */ private module Impl implements RegexTreeViewSig { @@ -141,8 +137,6 @@ private module Impl implements RegexTreeViewSig { exists(seqChild(re, start, end, 1)) // if a sequence does not have more than one element, it should be treated as that element instead. or this = TRegExpSpecialChar(re, start, end) - or - this = TRegExpNamedCharacterProperty(re, start, end) } /** @@ -183,8 +177,6 @@ private module Impl implements RegexTreeViewSig { result = this.(RegExpSequence).getChild(i) or result = this.(RegExpSpecialChar).getChild(i) - or - result = this.(RegExpNamedCharacterProperty).getChild(i) } /** @@ -1151,30 +1143,6 @@ private module Impl implements RegexTreeViewSig { override predicate isNullable() { this.getGroup().isNullable() } } - /** - * A named character property. For example, the POSIX bracket expression - * `[[:digit:]]`. - */ - additional class RegExpNamedCharacterProperty extends RegExpTerm, TRegExpNamedCharacterProperty { - RegExpNamedCharacterProperty() { this = TRegExpNamedCharacterProperty(re, start, end) } - - override RegExpTerm getChild(int i) { none() } - - override string getAPrimaryQlClass() { result = "RegExpNamedCharacterProperty" } - - /** - * Gets the property name. For example, in `\p{Space}`, the result is - * `"Space"`. - */ - string getName() { result = re.getCharacterPropertyName(start, end) } - - /** - * Holds if the property is inverted. For example, it holds for `\p{^Digit}`, - * which matches non-digits. - */ - predicate isInverted() { re.namedCharacterPropertyIsInverted(start, end) } - } - class Top = RegExpParent; /** @@ -1183,18 +1151,6 @@ private module Impl implements RegexTreeViewSig { */ predicate isEscapeClass(RegExpTerm term, string clazz) { exists(RegExpCharacterClassEscape escape | term = escape | escape.getValue() = clazz) - or - // TODO: expand to cover more properties - exists(RegExpNamedCharacterProperty escape | term = escape | - escape.getName().toLowerCase() = "digit" and - if escape.isInverted() then clazz = "D" else clazz = "d" - or - escape.getName().toLowerCase() = "space" and - if escape.isInverted() then clazz = "S" else clazz = "s" - or - escape.getName().toLowerCase() = "word" and - if escape.isInverted() then clazz = "W" else clazz = "w" - ) } /** diff --git a/cpp/ql/lib/semmle/code/cpp/regex/internal/ParseRegExp.qll b/cpp/ql/lib/semmle/code/cpp/regex/internal/ParseRegExp.qll index a7d0d38919a1..c30649a2897e 100644 --- a/cpp/ql/lib/semmle/code/cpp/regex/internal/ParseRegExp.qll +++ b/cpp/ql/lib/semmle/code/cpp/regex/internal/ParseRegExp.qll @@ -282,9 +282,8 @@ abstract class RegExp extends StringLiteral { ) } - /** Matches named character properties such as `\p{Word}` and `[[:digit:]]` */ + /** Matches named character properties such as `[[:digit:]]` */ predicate namedCharacterProperty(int start, int end, string name) { - this.pStyleNamedCharacterProperty(start, end, name) or this.posixStyleNamedCharacterProperty(start, end, name) } @@ -314,30 +313,6 @@ abstract class RegExp extends StringLiteral { ) } - /** - * Matches named character properties. For example: - * - `\p{Space}` - * - `\P{Digit}` upper-case P means inverted - * - `\p{^Word}` caret also means inverted - * - * These can occur both inside and outside of character classes. - */ - private predicate pStyleNamedCharacterProperty(int start, int end, string name) { - this.escapingChar(start) and - this.getChar(start + 1) in ["p", "P"] and - this.getChar(start + 2) = "{" and - this.getChar(end - 1) = "}" and - end > start and - not exists(int i | start + 2 < i and i < end - 1 | this.getChar(i) = "}") and - exists(int nameStart | - this.getChar(start + 3) = "^" and nameStart = start + 4 - or - not this.getChar(start + 3) = "^" and nameStart = start + 3 - | - name = this.getText().substring(nameStart, end - 1) - ) - } - /** * Holds if the named character property is inverted. Examples for which it holds: * - `\P{Digit}` upper-case P means inverted @@ -350,14 +325,6 @@ abstract class RegExp extends StringLiteral { * - `[[:alnum:]]` */ predicate namedCharacterPropertyIsInverted(int start, int end) { - this.pStyleNamedCharacterProperty(start, end, _) and - exists(boolean upperP, boolean caret | - (if this.getChar(start + 1) = "P" then upperP = true else upperP = false) and - (if this.getChar(start + 3) = "^" then caret = true else caret = false) - | - upperP.booleanXor(caret) = true - ) - or this.posixStyleNamedCharacterProperty(start, end, _) and this.getChar(start + 3) = "^" } @@ -371,7 +338,6 @@ abstract class RegExp extends StringLiteral { this.escapingChar(start) and not this.numberedBackreference(start, _, _) and not this.namedBackreference(start, _, _) and - not this.pStyleNamedCharacterProperty(start, _, _) and ( // hex char \xhh this.getChar(start + 1) = "x" and end = start + 4 @@ -447,9 +413,6 @@ abstract class RegExp extends StringLiteral { ) and not exists(int x, int y | this.groupStart(x, y) and x <= start and y >= end) and not exists(int x, int y | this.backreference(x, y) and x <= start and y >= end) and - not exists(int x, int y | - this.pStyleNamedCharacterProperty(x, y, _) and x <= start and y >= end - ) and not exists(int x, int y | this.multiples(x, y, _, _) and x <= start and y >= end) } @@ -776,8 +739,6 @@ abstract class RegExp extends StringLiteral { this.charSet(start, end) or this.backreference(start, end) - or - this.pStyleNamedCharacterProperty(start, end, _) } private predicate qualifier(int start, int end, boolean maybeEmpty, boolean mayRepeatForever) { diff --git a/cpp/ql/test/library-tests/regex/parse.expected b/cpp/ql/test/library-tests/regex/parse.expected index a01d9f6a61e5..70a73e7792ba 100644 --- a/cpp/ql/test/library-tests/regex/parse.expected +++ b/cpp/ql/test/library-tests/regex/parse.expected @@ -36,10 +36,6 @@ #-----| [RegExpConstant, RegExpNormalChar] f -#-----| [RegExpConstant, RegExpNormalChar] a - -#-----| [RegExpConstant, RegExpNormalChar] f - #-----| [RegExpConstant, RegExpNormalChar] q #-----| [RegExpCharacterClassEscape] \s @@ -249,26 +245,6 @@ #-----| 2 -> [RegExpOpt] c? #-----| 3 -> [RegExpConstant, RegExpNormalChar] d -#-----| [RegExpNamedCharacterProperty] [:digit:] - -#-----| [RegExpNamedCharacterProperty] [:digit:] - -#-----| [RegExpNamedCharacterProperty] [:alpha:] - -#-----| [RegExpNamedCharacterProperty] [:digit:] - -#-----| [RegExpNamedCharacterProperty] [:alpha:] - -#-----| [RegExpNamedCharacterProperty] [:digit:] - -#-----| [RegExpNamedCharacterProperty] \p{Digit} - -#-----| [RegExpNamedCharacterProperty] \p{^Alnum} - -#-----| [RegExpNamedCharacterProperty] \P{Digit} - -#-----| [RegExpNamedCharacterProperty] \p{Word} - #-----| [RegExpBackRef] \k #-----| [RegExpBackRef] \1 @@ -317,10 +293,6 @@ #-----| 0 -> [RegExpConstant, RegExpNormalChar] a #-----| 1 -> [RegExpConstant, RegExpNormalChar] f -#-----| [RegExpCharacterRange] a-f -#-----| 0 -> [RegExpConstant, RegExpNormalChar] a -#-----| 1 -> [RegExpConstant, RegExpNormalChar] f - #-----| [RegExpCharacterRange] A-Z #-----| 0 -> [RegExpConstant, RegExpNormalChar] A #-----| 1 -> [RegExpConstant, RegExpNormalChar] Z @@ -339,22 +311,12 @@ #-----| [RegExpCharacterClass] [A-F[:digit:]a-f] #-----| 0 -> [RegExpCharacterRange] A-F -#-----| 1 -> [RegExpNamedCharacterProperty] [:digit:] -#-----| 2 -> [RegExpCharacterRange] a-f #-----| [RegExpCharacterClass] [[:alpha:][:digit:]] -#-----| 0 -> [RegExpNamedCharacterProperty] [:alpha:] -#-----| 1 -> [RegExpNamedCharacterProperty] [:digit:] #-----| [RegExpCharacterClass] [[:alpha:]] -#-----| 0 -> [RegExpNamedCharacterProperty] [:alpha:] #-----| [RegExpCharacterClass] [[:digit:]] -#-----| 0 -> [RegExpNamedCharacterProperty] [:digit:] - -#-----| [RegExpCharacterClass] [a-f\p{Digit}] -#-----| 0 -> [RegExpCharacterRange] a-f -#-----| 1 -> [RegExpNamedCharacterProperty] \p{Digit} #-----| [RegExpCharacterClass] [[a-f] #-----| 0 -> [RegExpConstant, RegExpNormalChar] [ @@ -407,18 +369,6 @@ #-----| 0 -> [RegExpConstant, RegExpNormalChar] foo #-----| 1 -> [RegExpConstant, RegExpNormalChar] bar -#-----| [RegExpPlus] [a-f\p{Digit}]+ -#-----| 0 -> [RegExpCharacterClass] [a-f\p{Digit}] - -#-----| [RegExpRange] \p{^Alnum}{2,3} -#-----| 0 -> [RegExpNamedCharacterProperty] \p{^Alnum} - -#-----| [RegExpPlus] \P{Digit}+ -#-----| 0 -> [RegExpNamedCharacterProperty] \P{Digit} - -#-----| [RegExpStar] \p{Word}* -#-----| 0 -> [RegExpNamedCharacterProperty] \p{Word} - #-----| [RegExpPlus] q+ #-----| 0 -> [RegExpConstant, RegExpNormalChar] q diff --git a/cpp/ql/test/library-tests/regex/regexp.cpp b/cpp/ql/test/library-tests/regex/regexp.cpp index 4dc78d789f3b..083aed946e3e 100644 --- a/cpp/ql/test/library-tests/regex/regexp.cpp +++ b/cpp/ql/test/library-tests/regex/regexp.cpp @@ -66,12 +66,6 @@ std::regex r_ng2("(?'foo'fo+)"); // single-quote named-group form std::regex r_bref1("(a+)b+\\1"); std::regex r_bref2("(?q+)\\s+\\k+"); -// Named character properties using the p-style syntax -std::regex r_prop1("\\p{Word}*"); -std::regex r_prop2("\\P{Digit}+"); -std::regex r_prop3("\\p{^Alnum}{2,3}"); -std::regex r_prop4("[a-f\\p{Digit}]+"); // Also valid inside character classes - // Two separate character classes, each containing a single POSIX bracket expression std::regex r_posix1("[[:alpha:]][[:digit:]]"); diff --git a/cpp/ql/test/library-tests/regex/regexp.expected b/cpp/ql/test/library-tests/regex/regexp.expected index 770d2f201dd8..b9392f6a8120 100644 --- a/cpp/ql/test/library-tests/regex/regexp.expected +++ b/cpp/ql/test/library-tests/regex/regexp.expected @@ -49,12 +49,6 @@ term | file://:0:0:0:0 | Z | RegExpConstant,RegExpNormalChar | | file://:0:0:0:0 | [ | RegExpConstant,RegExpNormalChar | | file://:0:0:0:0 | [123] | RegExpCharacterClass | -| file://:0:0:0:0 | [:alpha:] | RegExpNamedCharacterProperty | -| file://:0:0:0:0 | [:alpha:] | RegExpNamedCharacterProperty | -| file://:0:0:0:0 | [:digit:] | RegExpNamedCharacterProperty | -| file://:0:0:0:0 | [:digit:] | RegExpNamedCharacterProperty | -| file://:0:0:0:0 | [:digit:] | RegExpNamedCharacterProperty | -| file://:0:0:0:0 | [:digit:] | RegExpNamedCharacterProperty | | file://:0:0:0:0 | [A-F[:digit:]a-f] | RegExpCharacterClass | | file://:0:0:0:0 | [[:alpha:][:digit:]] | RegExpCharacterClass | | file://:0:0:0:0 | [[:alpha:]] | RegExpCharacterClass | @@ -70,14 +64,10 @@ term | file://:0:0:0:0 | [^A-Z] | RegExpCharacterClass | | file://:0:0:0:0 | [^]] | RegExpCharacterClass | | file://:0:0:0:0 | [a-fA-F0-9_] | RegExpCharacterClass | -| file://:0:0:0:0 | [a-f\\p{Digit}] | RegExpCharacterClass | -| file://:0:0:0:0 | [a-f\\p{Digit}]+ | RegExpPlus | | file://:0:0:0:0 | [abc] | RegExpCharacterClass | | file://:0:0:0:0 | \\1 | RegExpBackRef | | file://:0:0:0:0 | \\B | RegExpNonWordBoundary | | file://:0:0:0:0 | \\D | RegExpCharacterClassEscape | -| file://:0:0:0:0 | \\P{Digit} | RegExpNamedCharacterProperty | -| file://:0:0:0:0 | \\P{Digit}+ | RegExpPlus | | file://:0:0:0:0 | \\S | RegExpCharacterClassEscape | | file://:0:0:0:0 | \\W | RegExpCharacterClassEscape | | file://:0:0:0:0 | \\[ | RegExpConstant,RegExpEscape | @@ -92,11 +82,6 @@ term | file://:0:0:0:0 | \\n | RegExpConstant,RegExpEscape | | file://:0:0:0:0 | \\n | RegExpConstant,RegExpEscape | | file://:0:0:0:0 | \\n\\r\\t | RegExpSequence | -| file://:0:0:0:0 | \\p{Digit} | RegExpNamedCharacterProperty | -| file://:0:0:0:0 | \\p{Word} | RegExpNamedCharacterProperty | -| file://:0:0:0:0 | \\p{Word}* | RegExpStar | -| file://:0:0:0:0 | \\p{^Alnum} | RegExpNamedCharacterProperty | -| file://:0:0:0:0 | \\p{^Alnum}{2,3} | RegExpRange | | file://:0:0:0:0 | \\r | RegExpConstant,RegExpEscape | | file://:0:0:0:0 | \\s | RegExpCharacterClassEscape | | file://:0:0:0:0 | \\s | RegExpCharacterClassEscape | @@ -127,14 +112,12 @@ term | file://:0:0:0:0 | a | RegExpConstant,RegExpNormalChar | | file://:0:0:0:0 | a | RegExpConstant,RegExpNormalChar | | file://:0:0:0:0 | a | RegExpConstant,RegExpNormalChar | -| file://:0:0:0:0 | a | RegExpConstant,RegExpNormalChar | | file://:0:0:0:0 | a* | RegExpStar | | file://:0:0:0:0 | a*b+c?d | RegExpSequence | | file://:0:0:0:0 | a+ | RegExpPlus | | file://:0:0:0:0 | a-f | RegExpCharacterRange | | file://:0:0:0:0 | a-f | RegExpCharacterRange | | file://:0:0:0:0 | a-f | RegExpCharacterRange | -| file://:0:0:0:0 | a-f | RegExpCharacterRange | | file://:0:0:0:0 | a\\nb | RegExpSequence | | file://:0:0:0:0 | a\|b\|cd | RegExpAlt | | file://:0:0:0:0 | abc | RegExpConstant,RegExpNormalChar | @@ -174,7 +157,6 @@ term | file://:0:0:0:0 | f | RegExpConstant,RegExpNormalChar | | file://:0:0:0:0 | f | RegExpConstant,RegExpNormalChar | | file://:0:0:0:0 | f | RegExpConstant,RegExpNormalChar | -| file://:0:0:0:0 | f | RegExpConstant,RegExpNormalChar | | file://:0:0:0:0 | fo | RegExpConstant,RegExpNormalChar | | file://:0:0:0:0 | fo(o\|b)ar | RegExpSequence | | file://:0:0:0:0 | fo+ | RegExpSequence | @@ -237,7 +219,6 @@ regExpNormalCharValue | file://:0:0:0:0 | a | a | | file://:0:0:0:0 | a | a | | file://:0:0:0:0 | a | a | -| file://:0:0:0:0 | a | a | | file://:0:0:0:0 | abc | abc | | file://:0:0:0:0 | abc | abc | | file://:0:0:0:0 | abc | abc | @@ -268,7 +249,6 @@ regExpNormalCharValue | file://:0:0:0:0 | f | f | | file://:0:0:0:0 | f | f | | file://:0:0:0:0 | f | f | -| file://:0:0:0:0 | f | f | | file://:0:0:0:0 | fo | fo | | file://:0:0:0:0 | foo | foo | | file://:0:0:0:0 | foo | foo | From d3b51dd3a31540ffcdc9be50fc9ef198a1da04bc Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 23 Jul 2026 10:09:02 +0000 Subject: [PATCH 10/26] C++: Remove Ruby-style (?#...) comment groups --- .../lib/semmle/code/cpp/regex/internal/ParseRegExp.qll | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/cpp/ql/lib/semmle/code/cpp/regex/internal/ParseRegExp.qll b/cpp/ql/lib/semmle/code/cpp/regex/internal/ParseRegExp.qll index c30649a2897e..430fb88ee48b 100644 --- a/cpp/ql/lib/semmle/code/cpp/regex/internal/ParseRegExp.qll +++ b/cpp/ql/lib/semmle/code/cpp/regex/internal/ParseRegExp.qll @@ -596,8 +596,6 @@ abstract class RegExp extends StringLiteral { or this.negativeLookbehindAssertionStart(start, end) or - this.commentGroupStart(start, end) - or this.simpleGroupStart(start, end) } @@ -674,14 +672,6 @@ abstract class RegExp extends StringLiteral { end = start + 4 } - /** Matches the start of a comment group, i.e. `(?#`. */ - private predicate commentGroupStart(int start, int end) { - this.isGroupStart(start) and - this.getChar(start + 1) = "?" and - this.getChar(start + 2) = "#" and - end = start + 3 - } - /** Matches the contents of a group. */ predicate groupContents(int start, int end, int inStart, int inEnd) { this.groupStart(start, inStart) and From dda4b0092261d93ce5e014bb69d2dc37324ebaad Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 23 Jul 2026 10:10:15 +0000 Subject: [PATCH 11/26] C++: Remove single-quote named capture groups --- .../semmle/code/cpp/regex/internal/ParseRegExp.qll | 5 ----- cpp/ql/test/library-tests/regex/parse.expected | 14 -------------- cpp/ql/test/library-tests/regex/regexp.cpp | 1 - cpp/ql/test/library-tests/regex/regexp.expected | 9 --------- 4 files changed, 29 deletions(-) diff --git a/cpp/ql/lib/semmle/code/cpp/regex/internal/ParseRegExp.qll b/cpp/ql/lib/semmle/code/cpp/regex/internal/ParseRegExp.qll index 430fb88ee48b..66c6031bb2e8 100644 --- a/cpp/ql/lib/semmle/code/cpp/regex/internal/ParseRegExp.qll +++ b/cpp/ql/lib/semmle/code/cpp/regex/internal/ParseRegExp.qll @@ -630,11 +630,6 @@ abstract class RegExp extends StringLiteral { nameEnd = min(int i | i > start + 3 and this.getChar(i) = ">") and end = nameEnd + 1 ) - or - this.getChar(start + 2) = "'" and - exists(int nameEnd | - nameEnd = min(int i | i > start + 2 and this.getChar(i) = "'") and end = nameEnd + 1 - ) ) } diff --git a/cpp/ql/test/library-tests/regex/parse.expected b/cpp/ql/test/library-tests/regex/parse.expected index 70a73e7792ba..5427d40f61c9 100644 --- a/cpp/ql/test/library-tests/regex/parse.expected +++ b/cpp/ql/test/library-tests/regex/parse.expected @@ -44,10 +44,6 @@ #-----| [RegExpConstant, RegExpNormalChar] b -#-----| [RegExpConstant, RegExpNormalChar] f - -#-----| [RegExpConstant, RegExpNormalChar] o - #-----| [RegExpCharacterClassEscape] \w #-----| [RegExpConstant, RegExpNormalChar] : @@ -187,10 +183,6 @@ #-----| 1 -> [RegExpPlus] b+ #-----| 2 -> [RegExpBackRef] \1 -#-----| [RegExpSequence] fo+ -#-----| 0 -> [RegExpConstant, RegExpNormalChar] f -#-----| 1 -> [RegExpPlus] o+ - #-----| [RegExpSequence] (?::+)\w #-----| 0 -> [RegExpGroup] (?::+) #-----| 1 -> [RegExpCharacterClassEscape] \w @@ -263,9 +255,6 @@ #-----| [RegExpGroup] (a+) #-----| 0 -> [RegExpPlus] a+ -#-----| [RegExpGroup] (?'foo'fo+) -#-----| 0 -> [RegExpSequence] fo+ - #-----| [RegExpGroup] (?\w+) #-----| 0 -> [RegExpPlus] \w+ @@ -384,9 +373,6 @@ #-----| [RegExpPlus] b+ #-----| 0 -> [RegExpConstant, RegExpNormalChar] b -#-----| [RegExpPlus] o+ -#-----| 0 -> [RegExpConstant, RegExpNormalChar] o - #-----| [RegExpPlus] \w+ #-----| 0 -> [RegExpCharacterClassEscape] \w diff --git a/cpp/ql/test/library-tests/regex/regexp.cpp b/cpp/ql/test/library-tests/regex/regexp.cpp index 083aed946e3e..397f28a47ab3 100644 --- a/cpp/ql/test/library-tests/regex/regexp.cpp +++ b/cpp/ql/test/library-tests/regex/regexp.cpp @@ -60,7 +60,6 @@ std::regex r_grp4("(?::+)\\w"); // Non-capturing group matching colons // Named groups std::regex r_ng1("(?\\w+)"); -std::regex r_ng2("(?'foo'fo+)"); // single-quote named-group form // Backreferences std::regex r_bref1("(a+)b+\\1"); diff --git a/cpp/ql/test/library-tests/regex/regexp.expected b/cpp/ql/test/library-tests/regex/regexp.expected index b9392f6a8120..75e66c987f5d 100644 --- a/cpp/ql/test/library-tests/regex/regexp.expected +++ b/cpp/ql/test/library-tests/regex/regexp.expected @@ -1,9 +1,7 @@ groupName -| file://:0:0:0:0 | (?'foo'fo+) | foo | | file://:0:0:0:0 | (?\\w+) | id | | file://:0:0:0:0 | (?q+) | qux | groupNumber -| file://:0:0:0:0 | (?'foo'fo+) | 1 | | file://:0:0:0:0 | (a+) | 1 | | file://:0:0:0:0 | (a\|b\|cd) | 1 | | file://:0:0:0:0 | (foo) | 1 | @@ -16,7 +14,6 @@ term | file://:0:0:0:0 | 3 | RegExpConstant,RegExpNormalChar | | file://:0:0:0:0 | 9 | RegExpConstant,RegExpNormalChar | | file://:0:0:0:0 | !a | RegExpConstant,RegExpNormalChar | -| file://:0:0:0:0 | (?'foo'fo+) | RegExpGroup | | file://:0:0:0:0 | (?::+) | RegExpGroup | | file://:0:0:0:0 | (?::+)\\w | RegExpSequence | | file://:0:0:0:0 | (?\\w+) | RegExpGroup | @@ -156,16 +153,12 @@ term | file://:0:0:0:0 | f | RegExpConstant,RegExpNormalChar | | file://:0:0:0:0 | f | RegExpConstant,RegExpNormalChar | | file://:0:0:0:0 | f | RegExpConstant,RegExpNormalChar | -| file://:0:0:0:0 | f | RegExpConstant,RegExpNormalChar | | file://:0:0:0:0 | fo | RegExpConstant,RegExpNormalChar | | file://:0:0:0:0 | fo(o\|b)ar | RegExpSequence | -| file://:0:0:0:0 | fo+ | RegExpSequence | | file://:0:0:0:0 | foo | RegExpConstant,RegExpNormalChar | | file://:0:0:0:0 | foo | RegExpConstant,RegExpNormalChar | | file://:0:0:0:0 | foo\|bar | RegExpAlt | | file://:0:0:0:0 | o | RegExpConstant,RegExpNormalChar | -| file://:0:0:0:0 | o | RegExpConstant,RegExpNormalChar | -| file://:0:0:0:0 | o+ | RegExpPlus | | file://:0:0:0:0 | o\|b | RegExpAlt | | file://:0:0:0:0 | q | RegExpConstant,RegExpNormalChar | | file://:0:0:0:0 | q+ | RegExpPlus | @@ -248,10 +241,8 @@ regExpNormalCharValue | file://:0:0:0:0 | f | f | | file://:0:0:0:0 | f | f | | file://:0:0:0:0 | f | f | -| file://:0:0:0:0 | f | f | | file://:0:0:0:0 | fo | fo | | file://:0:0:0:0 | foo | foo | | file://:0:0:0:0 | foo | foo | | file://:0:0:0:0 | o | o | -| file://:0:0:0:0 | o | o | | file://:0:0:0:0 | q | q | From 908764e6037583d0abe7a8ec6705a757db5ec1f7 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 23 Jul 2026 10:12:01 +0000 Subject: [PATCH 12/26] C++: Remove named capture groups --- .../code/cpp/regex/internal/ParseRegExp.qll | 31 ++----------------- .../test/library-tests/regex/parse.expected | 22 +++++-------- cpp/ql/test/library-tests/regex/regexp.cpp | 5 +-- .../test/library-tests/regex/regexp.expected | 15 +++------ 4 files changed, 15 insertions(+), 58 deletions(-) diff --git a/cpp/ql/lib/semmle/code/cpp/regex/internal/ParseRegExp.qll b/cpp/ql/lib/semmle/code/cpp/regex/internal/ParseRegExp.qll index 66c6031bb2e8..8951df78833e 100644 --- a/cpp/ql/lib/semmle/code/cpp/regex/internal/ParseRegExp.qll +++ b/cpp/ql/lib/semmle/code/cpp/regex/internal/ParseRegExp.qll @@ -502,13 +502,7 @@ abstract class RegExp extends StringLiteral { } /** Gets the name, if it has one, of the group in start,end */ - string getGroupName(int start, int end) { - this.group(start, end) and - exists(int nameEnd | - this.namedGroupStart(start, nameEnd) and - result = this.getText().substring(start + 3, nameEnd - 1) - ) - } + string getGroupName(int start, int end) { none() } /** Whether the text in the range start, end is a group and can match the empty string. */ predicate zeroWidthMatch(int start, int end) { @@ -586,8 +580,6 @@ abstract class RegExp extends StringLiteral { private predicate groupStart(int start, int end) { this.nonCapturingGroupStart(start, end) or - this.namedGroupStart(start, end) - or this.lookaheadAssertionStart(start, end) or this.negativeLookaheadAssertionStart(start, end) @@ -603,7 +595,7 @@ abstract class RegExp extends StringLiteral { private predicate nonCapturingGroupStart(int start, int end) { this.isGroupStart(start) and this.getChar(start + 1) = "?" and - this.getChar(start + 2) = [":", "=", "<", "!", "#"] and + this.getChar(start + 2) = [":", "=", "!", "#"] and end = start + 3 } @@ -614,25 +606,6 @@ abstract class RegExp extends StringLiteral { end = start + 1 } - /** - * Matches the start of a named group, such as: - * - `(?\w+)` - * - `(?'name'\w+)` - */ - private predicate namedGroupStart(int start, int end) { - this.isGroupStart(start) and - this.getChar(start + 1) = "?" and - ( - this.getChar(start + 2) = "<" and - not this.getChar(start + 3) = "=" and // (?<=foo) is a positive lookbehind assertion - not this.getChar(start + 3) = "!" and // (? start + 3 and this.getChar(i) = ">") and - end = nameEnd + 1 - ) - ) - } - /** Matches the start of a positive lookahead assertion, i.e. `(?=`. */ private predicate lookaheadAssertionStart(int start, int end) { this.isGroupStart(start) and diff --git a/cpp/ql/test/library-tests/regex/parse.expected b/cpp/ql/test/library-tests/regex/parse.expected index 5427d40f61c9..b242ae947120 100644 --- a/cpp/ql/test/library-tests/regex/parse.expected +++ b/cpp/ql/test/library-tests/regex/parse.expected @@ -44,8 +44,6 @@ #-----| [RegExpConstant, RegExpNormalChar] b -#-----| [RegExpCharacterClassEscape] \w - #-----| [RegExpConstant, RegExpNormalChar] : #-----| [RegExpCharacterClassEscape] \w @@ -173,10 +171,10 @@ #-----| 0 -> [RegExpCharacterClass] [[:alpha:]] #-----| 1 -> [RegExpCharacterClass] [[:digit:]] -#-----| [RegExpSequence] (?q+)\s+\k+ -#-----| 0 -> [RegExpGroup] (?q+) +#-----| [RegExpSequence] (q+)\s+\k+ +#-----| 0 -> [RegExpGroup] (q+) #-----| 1 -> [RegExpPlus] \s+ -#-----| 2 -> [RegExpPlus] \k+ +#-----| 2 -> [RegExpPlus] \k+ #-----| [RegExpSequence] (a+)b+\1 #-----| 0 -> [RegExpGroup] (a+) @@ -237,7 +235,7 @@ #-----| 2 -> [RegExpOpt] c? #-----| 3 -> [RegExpConstant, RegExpNormalChar] d -#-----| [RegExpBackRef] \k +#-----| [RegExpBackRef] \k #-----| [RegExpBackRef] \1 @@ -249,15 +247,12 @@ #-----| [RegExpDot] . -#-----| [RegExpGroup] (?q+) +#-----| [RegExpGroup] (q+) #-----| 0 -> [RegExpPlus] q+ #-----| [RegExpGroup] (a+) #-----| 0 -> [RegExpPlus] a+ -#-----| [RegExpGroup] (?\w+) -#-----| 0 -> [RegExpPlus] \w+ - #-----| [RegExpGroup] (?::+) #-----| 0 -> [RegExpPlus] :+ @@ -364,8 +359,8 @@ #-----| [RegExpPlus] \s+ #-----| 0 -> [RegExpCharacterClassEscape] \s -#-----| [RegExpPlus] \k+ -#-----| 0 -> [RegExpBackRef] \k +#-----| [RegExpPlus] \k+ +#-----| 0 -> [RegExpBackRef] \k #-----| [RegExpPlus] a+ #-----| 0 -> [RegExpConstant, RegExpNormalChar] a @@ -373,9 +368,6 @@ #-----| [RegExpPlus] b+ #-----| 0 -> [RegExpConstant, RegExpNormalChar] b -#-----| [RegExpPlus] \w+ -#-----| 0 -> [RegExpCharacterClassEscape] \w - #-----| [RegExpPlus] :+ #-----| 0 -> [RegExpConstant, RegExpNormalChar] : diff --git a/cpp/ql/test/library-tests/regex/regexp.cpp b/cpp/ql/test/library-tests/regex/regexp.cpp index 397f28a47ab3..b50fe9b65d34 100644 --- a/cpp/ql/test/library-tests/regex/regexp.cpp +++ b/cpp/ql/test/library-tests/regex/regexp.cpp @@ -58,12 +58,9 @@ std::regex r_grp2("fo(o|b)ar"); std::regex r_grp3("(a|b|cd)e"); std::regex r_grp4("(?::+)\\w"); // Non-capturing group matching colons -// Named groups -std::regex r_ng1("(?\\w+)"); - // Backreferences std::regex r_bref1("(a+)b+\\1"); -std::regex r_bref2("(?q+)\\s+\\k+"); +std::regex r_bref2("(q+)\\s+\\k+"); // Two separate character classes, each containing a single POSIX bracket expression std::regex r_posix1("[[:alpha:]][[:digit:]]"); diff --git a/cpp/ql/test/library-tests/regex/regexp.expected b/cpp/ql/test/library-tests/regex/regexp.expected index 75e66c987f5d..7f6eb7afd1f2 100644 --- a/cpp/ql/test/library-tests/regex/regexp.expected +++ b/cpp/ql/test/library-tests/regex/regexp.expected @@ -1,11 +1,10 @@ groupName -| file://:0:0:0:0 | (?\\w+) | id | -| file://:0:0:0:0 | (?q+) | qux | groupNumber | file://:0:0:0:0 | (a+) | 1 | | file://:0:0:0:0 | (a\|b\|cd) | 1 | | file://:0:0:0:0 | (foo) | 1 | | file://:0:0:0:0 | (o\|b) | 1 | +| file://:0:0:0:0 | (q+) | 1 | term | file://:0:0:0:0 | 0 | RegExpConstant,RegExpNormalChar | | file://:0:0:0:0 | 0-9 | RegExpCharacterRange | @@ -16,9 +15,6 @@ term | file://:0:0:0:0 | !a | RegExpConstant,RegExpNormalChar | | file://:0:0:0:0 | (?::+) | RegExpGroup | | file://:0:0:0:0 | (?::+)\\w | RegExpSequence | -| file://:0:0:0:0 | (?\\w+) | RegExpGroup | -| file://:0:0:0:0 | (?q+) | RegExpGroup | -| file://:0:0:0:0 | (?q+)\\s+\\k+ | RegExpSequence | | file://:0:0:0:0 | (a+) | RegExpGroup | | file://:0:0:0:0 | (a+)b+\\1 | RegExpSequence | | file://:0:0:0:0 | (a\|b\|cd) | RegExpGroup | @@ -27,6 +23,8 @@ term | file://:0:0:0:0 | (foo)* | RegExpStar | | file://:0:0:0:0 | (foo)*bar | RegExpSequence | | file://:0:0:0:0 | (o\|b) | RegExpGroup | +| file://:0:0:0:0 | (q+) | RegExpGroup | +| file://:0:0:0:0 | (q+)\\s+\\k+ | RegExpSequence | | file://:0:0:0:0 | - | RegExpConstant,RegExpNormalChar | | file://:0:0:0:0 | . | RegExpDot | | file://:0:0:0:0 | . | RegExpDot | @@ -74,8 +72,8 @@ term | file://:0:0:0:0 | \\b!a\\B | RegExpSequence | | file://:0:0:0:0 | \\d | RegExpCharacterClassEscape | | file://:0:0:0:0 | \\d\\D | RegExpSequence | -| file://:0:0:0:0 | \\k | RegExpBackRef | -| file://:0:0:0:0 | \\k+ | RegExpPlus | +| file://:0:0:0:0 | \\k | RegExpBackRef | +| file://:0:0:0:0 | \\k+ | RegExpPlus | | file://:0:0:0:0 | \\n | RegExpConstant,RegExpEscape | | file://:0:0:0:0 | \\n | RegExpConstant,RegExpEscape | | file://:0:0:0:0 | \\n\\r\\t | RegExpSequence | @@ -89,8 +87,6 @@ term | file://:0:0:0:0 | \\w | RegExpCharacterClassEscape | | file://:0:0:0:0 | \\w | RegExpCharacterClassEscape | | file://:0:0:0:0 | \\w | RegExpCharacterClassEscape | -| file://:0:0:0:0 | \\w | RegExpCharacterClassEscape | -| file://:0:0:0:0 | \\w+ | RegExpPlus | | file://:0:0:0:0 | \\w+ | RegExpPlus | | file://:0:0:0:0 | \\w+\\W | RegExpSequence | | file://:0:0:0:0 | \| | RegExpConstant,RegExpNormalChar | @@ -195,7 +191,6 @@ regExpNormalCharValue | file://:0:0:0:0 | \\w | w | | file://:0:0:0:0 | \\w | w | | file://:0:0:0:0 | \\w | w | -| file://:0:0:0:0 | \\w | w | | file://:0:0:0:0 | \| | \| | | file://:0:0:0:0 | ] | ] | | file://:0:0:0:0 | ] | ] | From 0323da39c99d596ea6010f3f24f630b3391fcbf5 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 23 Jul 2026 10:13:23 +0000 Subject: [PATCH 13/26] C++: Remove named backreferences --- .../code/cpp/regex/internal/ParseRegExp.qll | 16 +------------ .../test/library-tests/regex/parse.expected | 23 ------------------- cpp/ql/test/library-tests/regex/regexp.cpp | 1 - .../test/library-tests/regex/regexp.expected | 11 --------- 4 files changed, 1 insertion(+), 50 deletions(-) diff --git a/cpp/ql/lib/semmle/code/cpp/regex/internal/ParseRegExp.qll b/cpp/ql/lib/semmle/code/cpp/regex/internal/ParseRegExp.qll index 8951df78833e..baa8d6c3556d 100644 --- a/cpp/ql/lib/semmle/code/cpp/regex/internal/ParseRegExp.qll +++ b/cpp/ql/lib/semmle/code/cpp/regex/internal/ParseRegExp.qll @@ -337,7 +337,6 @@ abstract class RegExp extends StringLiteral { predicate escapedCharacter(int start, int end) { this.escapingChar(start) and not this.numberedBackreference(start, _, _) and - not this.namedBackreference(start, _, _) and ( // hex char \xhh this.getChar(start + 1) = "x" and end = start + 4 @@ -648,17 +647,6 @@ abstract class RegExp extends StringLiteral { this.isGroupEnd(inEnd) } - /** Matches a named backreference, e.g. `\k`. */ - predicate namedBackreference(int start, int end, string name) { - this.escapingChar(start) and - this.getChar(start + 1) = "k" and - this.getChar(start + 2) = "<" and - exists(int nameEnd | nameEnd = min(int i | i > start + 3 and this.getChar(i) = ">") | - end = nameEnd + 1 and - name = this.getText().substring(start + 3, nameEnd) - ) - } - /** Matches a numbered backreference, e.g. `\1`. */ predicate numberedBackreference(int start, int end, int value) { this.escapingChar(start) and @@ -678,15 +666,13 @@ abstract class RegExp extends StringLiteral { /** Whether the text in the range `start,end` is a back reference */ predicate backreference(int start, int end) { this.numberedBackreference(start, end, _) - or - this.namedBackreference(start, end, _) } /** Gets the number of the back reference in start,end */ int getBackRefNumber(int start, int end) { this.numberedBackreference(start, end, result) } /** Gets the name, if it has one, of the back reference in start,end */ - string getBackRefName(int start, int end) { this.namedBackreference(start, end, result) } + string getBackRefName(int start, int end) { none() } private predicate baseItem(int start, int end) { this.characterItem(start, end) and diff --git a/cpp/ql/test/library-tests/regex/parse.expected b/cpp/ql/test/library-tests/regex/parse.expected index b242ae947120..2224556cd521 100644 --- a/cpp/ql/test/library-tests/regex/parse.expected +++ b/cpp/ql/test/library-tests/regex/parse.expected @@ -36,10 +36,6 @@ #-----| [RegExpConstant, RegExpNormalChar] f -#-----| [RegExpConstant, RegExpNormalChar] q - -#-----| [RegExpCharacterClassEscape] \s - #-----| [RegExpConstant, RegExpNormalChar] a #-----| [RegExpConstant, RegExpNormalChar] b @@ -171,11 +167,6 @@ #-----| 0 -> [RegExpCharacterClass] [[:alpha:]] #-----| 1 -> [RegExpCharacterClass] [[:digit:]] -#-----| [RegExpSequence] (q+)\s+\k+ -#-----| 0 -> [RegExpGroup] (q+) -#-----| 1 -> [RegExpPlus] \s+ -#-----| 2 -> [RegExpPlus] \k+ - #-----| [RegExpSequence] (a+)b+\1 #-----| 0 -> [RegExpGroup] (a+) #-----| 1 -> [RegExpPlus] b+ @@ -235,8 +226,6 @@ #-----| 2 -> [RegExpOpt] c? #-----| 3 -> [RegExpConstant, RegExpNormalChar] d -#-----| [RegExpBackRef] \k - #-----| [RegExpBackRef] \1 #-----| [RegExpSpecialChar] \b @@ -247,9 +236,6 @@ #-----| [RegExpDot] . -#-----| [RegExpGroup] (q+) -#-----| 0 -> [RegExpPlus] q+ - #-----| [RegExpGroup] (a+) #-----| 0 -> [RegExpPlus] a+ @@ -353,15 +339,6 @@ #-----| 0 -> [RegExpConstant, RegExpNormalChar] foo #-----| 1 -> [RegExpConstant, RegExpNormalChar] bar -#-----| [RegExpPlus] q+ -#-----| 0 -> [RegExpConstant, RegExpNormalChar] q - -#-----| [RegExpPlus] \s+ -#-----| 0 -> [RegExpCharacterClassEscape] \s - -#-----| [RegExpPlus] \k+ -#-----| 0 -> [RegExpBackRef] \k - #-----| [RegExpPlus] a+ #-----| 0 -> [RegExpConstant, RegExpNormalChar] a diff --git a/cpp/ql/test/library-tests/regex/regexp.cpp b/cpp/ql/test/library-tests/regex/regexp.cpp index b50fe9b65d34..3f8330a0a595 100644 --- a/cpp/ql/test/library-tests/regex/regexp.cpp +++ b/cpp/ql/test/library-tests/regex/regexp.cpp @@ -60,7 +60,6 @@ std::regex r_grp4("(?::+)\\w"); // Non-capturing group matching colons // Backreferences std::regex r_bref1("(a+)b+\\1"); -std::regex r_bref2("(q+)\\s+\\k+"); // Two separate character classes, each containing a single POSIX bracket expression std::regex r_posix1("[[:alpha:]][[:digit:]]"); diff --git a/cpp/ql/test/library-tests/regex/regexp.expected b/cpp/ql/test/library-tests/regex/regexp.expected index 7f6eb7afd1f2..ddac96dd5532 100644 --- a/cpp/ql/test/library-tests/regex/regexp.expected +++ b/cpp/ql/test/library-tests/regex/regexp.expected @@ -4,7 +4,6 @@ groupNumber | file://:0:0:0:0 | (a\|b\|cd) | 1 | | file://:0:0:0:0 | (foo) | 1 | | file://:0:0:0:0 | (o\|b) | 1 | -| file://:0:0:0:0 | (q+) | 1 | term | file://:0:0:0:0 | 0 | RegExpConstant,RegExpNormalChar | | file://:0:0:0:0 | 0-9 | RegExpCharacterRange | @@ -23,8 +22,6 @@ term | file://:0:0:0:0 | (foo)* | RegExpStar | | file://:0:0:0:0 | (foo)*bar | RegExpSequence | | file://:0:0:0:0 | (o\|b) | RegExpGroup | -| file://:0:0:0:0 | (q+) | RegExpGroup | -| file://:0:0:0:0 | (q+)\\s+\\k+ | RegExpSequence | | file://:0:0:0:0 | - | RegExpConstant,RegExpNormalChar | | file://:0:0:0:0 | . | RegExpDot | | file://:0:0:0:0 | . | RegExpDot | @@ -72,15 +69,11 @@ term | file://:0:0:0:0 | \\b!a\\B | RegExpSequence | | file://:0:0:0:0 | \\d | RegExpCharacterClassEscape | | file://:0:0:0:0 | \\d\\D | RegExpSequence | -| file://:0:0:0:0 | \\k | RegExpBackRef | -| file://:0:0:0:0 | \\k+ | RegExpPlus | | file://:0:0:0:0 | \\n | RegExpConstant,RegExpEscape | | file://:0:0:0:0 | \\n | RegExpConstant,RegExpEscape | | file://:0:0:0:0 | \\n\\r\\t | RegExpSequence | | file://:0:0:0:0 | \\r | RegExpConstant,RegExpEscape | | file://:0:0:0:0 | \\s | RegExpCharacterClassEscape | -| file://:0:0:0:0 | \\s | RegExpCharacterClassEscape | -| file://:0:0:0:0 | \\s+ | RegExpPlus | | file://:0:0:0:0 | \\s\\S | RegExpSequence | | file://:0:0:0:0 | \\t | RegExpConstant,RegExpEscape | | file://:0:0:0:0 | \\u{987 | RegExpConstant,RegExpEscape | @@ -156,8 +149,6 @@ term | file://:0:0:0:0 | foo\|bar | RegExpAlt | | file://:0:0:0:0 | o | RegExpConstant,RegExpNormalChar | | file://:0:0:0:0 | o\|b | RegExpAlt | -| file://:0:0:0:0 | q | RegExpConstant,RegExpNormalChar | -| file://:0:0:0:0 | q+ | RegExpPlus | regExpNormalCharValue | file://:0:0:0:0 | 0 | 0 | | file://:0:0:0:0 | 1 | 1 | @@ -185,7 +176,6 @@ regExpNormalCharValue | file://:0:0:0:0 | \\n | \n | | file://:0:0:0:0 | \\r | \r | | file://:0:0:0:0 | \\s | s | -| file://:0:0:0:0 | \\s | s | | file://:0:0:0:0 | \\t | \t | | file://:0:0:0:0 | \\u{987 | \u0987 | | file://:0:0:0:0 | \\w | w | @@ -240,4 +230,3 @@ regExpNormalCharValue | file://:0:0:0:0 | foo | foo | | file://:0:0:0:0 | foo | foo | | file://:0:0:0:0 | o | o | -| file://:0:0:0:0 | q | q | From 8e6b168730266552a46f51968213637f0e4d539a Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 23 Jul 2026 10:15:43 +0000 Subject: [PATCH 14/26] C++: Remove lookbehind assertions --- .../semmle/code/cpp/regex/RegexTreeView.qll | 36 ++------------- .../code/cpp/regex/internal/ParseRegExp.qll | 46 +------------------ 2 files changed, 4 insertions(+), 78 deletions(-) diff --git a/cpp/ql/lib/semmle/code/cpp/regex/RegexTreeView.qll b/cpp/ql/lib/semmle/code/cpp/regex/RegexTreeView.qll index 939038dd7227..8eef64c9dc08 100644 --- a/cpp/ql/lib/semmle/code/cpp/regex/RegexTreeView.qll +++ b/cpp/ql/lib/semmle/code/cpp/regex/RegexTreeView.qll @@ -991,15 +991,13 @@ private module Impl implements RegexTreeViewSig { } /** - * A zero-width lookahead or lookbehind assertion. + * A zero-width lookahead assertion. * * Examples: * * ``` * (?=\w) * (?!\n) - * (?<=\.) - * (? Date: Thu, 23 Jul 2026 10:16:18 +0000 Subject: [PATCH 15/26] C++: Add control-escape tests (pre-fix) --- cpp/ql/test/library-tests/regex/parse.expected | 16 ++++++++++++++++ cpp/ql/test/library-tests/regex/regexp.cpp | 4 ++++ cpp/ql/test/library-tests/regex/regexp.expected | 10 ++++++++++ 3 files changed, 30 insertions(+) diff --git a/cpp/ql/test/library-tests/regex/parse.expected b/cpp/ql/test/library-tests/regex/parse.expected index 2224556cd521..0f07ba72809f 100644 --- a/cpp/ql/test/library-tests/regex/parse.expected +++ b/cpp/ql/test/library-tests/regex/parse.expected @@ -26,6 +26,14 @@ #-----| [RegExpConstant, RegExpNormalChar] b +#-----| [RegExpConstant, RegExpEscape] \c + +#-----| [RegExpConstant, RegExpNormalChar] Z + +#-----| [RegExpConstant, RegExpEscape] \c + +#-----| [RegExpConstant, RegExpNormalChar] A + #-----| [RegExpConstant, RegExpEscape] \u{987 #-----| [RegExpConstant, RegExpNormalChar] A @@ -163,6 +171,10 @@ #-----| 1 -> [RegExpConstant, RegExpEscape] \n #-----| 2 -> [RegExpConstant, RegExpNormalChar] b +#-----| [RegExpSequence] \cA +#-----| 0 -> [RegExpConstant, RegExpEscape] \c +#-----| 1 -> [RegExpConstant, RegExpNormalChar] A + #-----| [RegExpSequence] [[:alpha:]][[:digit:]] #-----| 0 -> [RegExpCharacterClass] [[:alpha:]] #-----| 1 -> [RegExpCharacterClass] [[:digit:]] @@ -279,6 +291,10 @@ #-----| 0 -> [RegExpConstant, RegExpNormalChar] 0 #-----| 1 -> [RegExpConstant, RegExpNormalChar] 9 +#-----| [RegExpCharacterClass] [\cZ] +#-----| 0 -> [RegExpConstant, RegExpEscape] \c +#-----| 1 -> [RegExpConstant, RegExpNormalChar] Z + #-----| [RegExpCharacterClass] [A-F[:digit:]a-f] #-----| 0 -> [RegExpCharacterRange] A-F diff --git a/cpp/ql/test/library-tests/regex/regexp.cpp b/cpp/ql/test/library-tests/regex/regexp.cpp index 3f8330a0a595..86352695dc5a 100644 --- a/cpp/ql/test/library-tests/regex/regexp.cpp +++ b/cpp/ql/test/library-tests/regex/regexp.cpp @@ -76,6 +76,10 @@ std::regex r_posix4("[:digit:]"); // unicode std::regex r_uni("\\u{9879}"); +// control escapes +std::regex r_ctrl1("\\cA"); +std::regex r_ctrl2("[\\cZ]"); + // String literal spellings for location tests std::regex r_loc_plain("a\\nb"); std::basic_regex r_loc_L(L"abc"); diff --git a/cpp/ql/test/library-tests/regex/regexp.expected b/cpp/ql/test/library-tests/regex/regexp.expected index ddac96dd5532..3f3c8b64604b 100644 --- a/cpp/ql/test/library-tests/regex/regexp.expected +++ b/cpp/ql/test/library-tests/regex/regexp.expected @@ -32,6 +32,7 @@ term | file://:0:0:0:0 | A | RegExpConstant,RegExpNormalChar | | file://:0:0:0:0 | A | RegExpConstant,RegExpNormalChar | | file://:0:0:0:0 | A | RegExpConstant,RegExpNormalChar | +| file://:0:0:0:0 | A | RegExpConstant,RegExpNormalChar | | file://:0:0:0:0 | A-F | RegExpCharacterRange | | file://:0:0:0:0 | A-F | RegExpCharacterRange | | file://:0:0:0:0 | A-F] | RegExpConstant,RegExpNormalChar | @@ -39,6 +40,7 @@ term | file://:0:0:0:0 | F | RegExpConstant,RegExpNormalChar | | file://:0:0:0:0 | F | RegExpConstant,RegExpNormalChar | | file://:0:0:0:0 | Z | RegExpConstant,RegExpNormalChar | +| file://:0:0:0:0 | Z | RegExpConstant,RegExpNormalChar | | file://:0:0:0:0 | [ | RegExpConstant,RegExpNormalChar | | file://:0:0:0:0 | [123] | RegExpCharacterClass | | file://:0:0:0:0 | [A-F[:digit:]a-f] | RegExpCharacterClass | @@ -48,6 +50,7 @@ term | file://:0:0:0:0 | [[:digit:]] | RegExpCharacterClass | | file://:0:0:0:0 | [[a-f] | RegExpCharacterClass | | file://:0:0:0:0 | [[a-f]A-F] | RegExpSequence | +| file://:0:0:0:0 | [\\cZ] | RegExpCharacterClass | | file://:0:0:0:0 | [\\w] | RegExpCharacterClass | | file://:0:0:0:0 | [\\w]+ | RegExpPlus | | file://:0:0:0:0 | [\|] | RegExpCharacterClass | @@ -67,6 +70,9 @@ term | file://:0:0:0:0 | \\] | RegExpConstant,RegExpEscape | | file://:0:0:0:0 | \\b | RegExpSpecialChar | | file://:0:0:0:0 | \\b!a\\B | RegExpSequence | +| file://:0:0:0:0 | \\c | RegExpConstant,RegExpEscape | +| file://:0:0:0:0 | \\c | RegExpConstant,RegExpEscape | +| file://:0:0:0:0 | \\cA | RegExpSequence | | file://:0:0:0:0 | \\d | RegExpCharacterClassEscape | | file://:0:0:0:0 | \\d\\D | RegExpSequence | | file://:0:0:0:0 | \\n | RegExpConstant,RegExpEscape | @@ -161,16 +167,20 @@ regExpNormalCharValue | file://:0:0:0:0 | A | A | | file://:0:0:0:0 | A | A | | file://:0:0:0:0 | A | A | +| file://:0:0:0:0 | A | A | | file://:0:0:0:0 | A-F] | A-F] | | file://:0:0:0:0 | F | F | | file://:0:0:0:0 | F | F | | file://:0:0:0:0 | Z | Z | +| file://:0:0:0:0 | Z | Z | | file://:0:0:0:0 | [ | [ | | file://:0:0:0:0 | \\D | D | | file://:0:0:0:0 | \\S | S | | file://:0:0:0:0 | \\W | W | | file://:0:0:0:0 | \\[ | [ | | file://:0:0:0:0 | \\] | ] | +| file://:0:0:0:0 | \\c | c | +| file://:0:0:0:0 | \\c | c | | file://:0:0:0:0 | \\d | d | | file://:0:0:0:0 | \\n | \n | | file://:0:0:0:0 | \\n | \n | From 31ae5fe02130be1ad9b15fac0d61e85970d6baf9 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 23 Jul 2026 10:17:31 +0000 Subject: [PATCH 16/26] C++: Implement \cX control escapes --- .../code/cpp/regex/internal/ParseRegExp.qll | 5 ++++- cpp/ql/test/library-tests/regex/parse.expected | 15 +++------------ cpp/ql/test/library-tests/regex/regexp.expected | 13 ++++--------- 3 files changed, 11 insertions(+), 22 deletions(-) diff --git a/cpp/ql/lib/semmle/code/cpp/regex/internal/ParseRegExp.qll b/cpp/ql/lib/semmle/code/cpp/regex/internal/ParseRegExp.qll index c84091b063fb..191d91990da1 100644 --- a/cpp/ql/lib/semmle/code/cpp/regex/internal/ParseRegExp.qll +++ b/cpp/ql/lib/semmle/code/cpp/regex/internal/ParseRegExp.qll @@ -344,8 +344,11 @@ abstract class RegExp extends StringLiteral { // wide hex char \uhhhh this.getChar(start + 1) = "u" and end = start + 6 or + // control char \cX + this.getChar(start + 1) = "c" and end = start + 3 + or // escape not handled above; update when adding a new case - not this.getChar(start + 1) in ["x", "u"] and + not this.getChar(start + 1) in ["x", "u", "c"] and not exists(this.getChar(start + 1).toInt()) and end = start + 2 ) diff --git a/cpp/ql/test/library-tests/regex/parse.expected b/cpp/ql/test/library-tests/regex/parse.expected index 0f07ba72809f..b2f12c744a07 100644 --- a/cpp/ql/test/library-tests/regex/parse.expected +++ b/cpp/ql/test/library-tests/regex/parse.expected @@ -26,13 +26,9 @@ #-----| [RegExpConstant, RegExpNormalChar] b -#-----| [RegExpConstant, RegExpEscape] \c +#-----| [RegExpConstant, RegExpEscape] \cZ -#-----| [RegExpConstant, RegExpNormalChar] Z - -#-----| [RegExpConstant, RegExpEscape] \c - -#-----| [RegExpConstant, RegExpNormalChar] A +#-----| [RegExpConstant, RegExpEscape] \cA #-----| [RegExpConstant, RegExpEscape] \u{987 @@ -171,10 +167,6 @@ #-----| 1 -> [RegExpConstant, RegExpEscape] \n #-----| 2 -> [RegExpConstant, RegExpNormalChar] b -#-----| [RegExpSequence] \cA -#-----| 0 -> [RegExpConstant, RegExpEscape] \c -#-----| 1 -> [RegExpConstant, RegExpNormalChar] A - #-----| [RegExpSequence] [[:alpha:]][[:digit:]] #-----| 0 -> [RegExpCharacterClass] [[:alpha:]] #-----| 1 -> [RegExpCharacterClass] [[:digit:]] @@ -292,8 +284,7 @@ #-----| 1 -> [RegExpConstant, RegExpNormalChar] 9 #-----| [RegExpCharacterClass] [\cZ] -#-----| 0 -> [RegExpConstant, RegExpEscape] \c -#-----| 1 -> [RegExpConstant, RegExpNormalChar] Z +#-----| 0 -> [RegExpConstant, RegExpEscape] \cZ #-----| [RegExpCharacterClass] [A-F[:digit:]a-f] #-----| 0 -> [RegExpCharacterRange] A-F diff --git a/cpp/ql/test/library-tests/regex/regexp.expected b/cpp/ql/test/library-tests/regex/regexp.expected index 3f3c8b64604b..0a5cfb87b6b0 100644 --- a/cpp/ql/test/library-tests/regex/regexp.expected +++ b/cpp/ql/test/library-tests/regex/regexp.expected @@ -32,7 +32,6 @@ term | file://:0:0:0:0 | A | RegExpConstant,RegExpNormalChar | | file://:0:0:0:0 | A | RegExpConstant,RegExpNormalChar | | file://:0:0:0:0 | A | RegExpConstant,RegExpNormalChar | -| file://:0:0:0:0 | A | RegExpConstant,RegExpNormalChar | | file://:0:0:0:0 | A-F | RegExpCharacterRange | | file://:0:0:0:0 | A-F | RegExpCharacterRange | | file://:0:0:0:0 | A-F] | RegExpConstant,RegExpNormalChar | @@ -40,7 +39,6 @@ term | file://:0:0:0:0 | F | RegExpConstant,RegExpNormalChar | | file://:0:0:0:0 | F | RegExpConstant,RegExpNormalChar | | file://:0:0:0:0 | Z | RegExpConstant,RegExpNormalChar | -| file://:0:0:0:0 | Z | RegExpConstant,RegExpNormalChar | | file://:0:0:0:0 | [ | RegExpConstant,RegExpNormalChar | | file://:0:0:0:0 | [123] | RegExpCharacterClass | | file://:0:0:0:0 | [A-F[:digit:]a-f] | RegExpCharacterClass | @@ -70,9 +68,8 @@ term | file://:0:0:0:0 | \\] | RegExpConstant,RegExpEscape | | file://:0:0:0:0 | \\b | RegExpSpecialChar | | file://:0:0:0:0 | \\b!a\\B | RegExpSequence | -| file://:0:0:0:0 | \\c | RegExpConstant,RegExpEscape | -| file://:0:0:0:0 | \\c | RegExpConstant,RegExpEscape | -| file://:0:0:0:0 | \\cA | RegExpSequence | +| file://:0:0:0:0 | \\cA | RegExpConstant,RegExpEscape | +| file://:0:0:0:0 | \\cZ | RegExpConstant,RegExpEscape | | file://:0:0:0:0 | \\d | RegExpCharacterClassEscape | | file://:0:0:0:0 | \\d\\D | RegExpSequence | | file://:0:0:0:0 | \\n | RegExpConstant,RegExpEscape | @@ -167,20 +164,18 @@ regExpNormalCharValue | file://:0:0:0:0 | A | A | | file://:0:0:0:0 | A | A | | file://:0:0:0:0 | A | A | -| file://:0:0:0:0 | A | A | | file://:0:0:0:0 | A-F] | A-F] | | file://:0:0:0:0 | F | F | | file://:0:0:0:0 | F | F | | file://:0:0:0:0 | Z | Z | -| file://:0:0:0:0 | Z | Z | | file://:0:0:0:0 | [ | [ | | file://:0:0:0:0 | \\D | D | | file://:0:0:0:0 | \\S | S | | file://:0:0:0:0 | \\W | W | | file://:0:0:0:0 | \\[ | [ | | file://:0:0:0:0 | \\] | ] | -| file://:0:0:0:0 | \\c | c | -| file://:0:0:0:0 | \\c | c | +| file://:0:0:0:0 | \\cA | cA | +| file://:0:0:0:0 | \\cZ | cZ | | file://:0:0:0:0 | \\d | d | | file://:0:0:0:0 | \\n | \n | | file://:0:0:0:0 | \\n | \n | From c49213f66cc531be7ea8440a6be537315bda19b0 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 23 Jul 2026 10:18:01 +0000 Subject: [PATCH 17/26] C++: Add NUL-escape tests (pre-fix) --- cpp/ql/test/library-tests/regex/parse.expected | 10 ++++++++++ cpp/ql/test/library-tests/regex/regexp.cpp | 4 ++++ cpp/ql/test/library-tests/regex/regexp.expected | 7 +++++++ 3 files changed, 21 insertions(+) diff --git a/cpp/ql/test/library-tests/regex/parse.expected b/cpp/ql/test/library-tests/regex/parse.expected index b2f12c744a07..b7d2e50a0628 100644 --- a/cpp/ql/test/library-tests/regex/parse.expected +++ b/cpp/ql/test/library-tests/regex/parse.expected @@ -26,6 +26,12 @@ #-----| [RegExpConstant, RegExpNormalChar] b +#-----| [RegExpConstant, RegExpNormalChar] \ + +#-----| [RegExpConstant, RegExpNormalChar] 0 + +#-----| [RegExpConstant, RegExpNormalChar] \0 + #-----| [RegExpConstant, RegExpEscape] \cZ #-----| [RegExpConstant, RegExpEscape] \cA @@ -283,6 +289,10 @@ #-----| 0 -> [RegExpConstant, RegExpNormalChar] 0 #-----| 1 -> [RegExpConstant, RegExpNormalChar] 9 +#-----| [RegExpCharacterClass] [\0] +#-----| 0 -> [RegExpConstant, RegExpNormalChar] \ +#-----| 1 -> [RegExpConstant, RegExpNormalChar] 0 + #-----| [RegExpCharacterClass] [\cZ] #-----| 0 -> [RegExpConstant, RegExpEscape] \cZ diff --git a/cpp/ql/test/library-tests/regex/regexp.cpp b/cpp/ql/test/library-tests/regex/regexp.cpp index 86352695dc5a..18c3b8d3e484 100644 --- a/cpp/ql/test/library-tests/regex/regexp.cpp +++ b/cpp/ql/test/library-tests/regex/regexp.cpp @@ -80,6 +80,10 @@ std::regex r_uni("\\u{9879}"); std::regex r_ctrl1("\\cA"); std::regex r_ctrl2("[\\cZ]"); +// NUL escape +std::regex r_nul1("\\0"); +std::regex r_nul2("[\\0]"); + // String literal spellings for location tests std::regex r_loc_plain("a\\nb"); std::basic_regex r_loc_L(L"abc"); diff --git a/cpp/ql/test/library-tests/regex/regexp.expected b/cpp/ql/test/library-tests/regex/regexp.expected index 0a5cfb87b6b0..b2c734087d6b 100644 --- a/cpp/ql/test/library-tests/regex/regexp.expected +++ b/cpp/ql/test/library-tests/regex/regexp.expected @@ -6,6 +6,7 @@ groupNumber | file://:0:0:0:0 | (o\|b) | 1 | term | file://:0:0:0:0 | 0 | RegExpConstant,RegExpNormalChar | +| file://:0:0:0:0 | 0 | RegExpConstant,RegExpNormalChar | | file://:0:0:0:0 | 0-9 | RegExpCharacterRange | | file://:0:0:0:0 | 1 | RegExpConstant,RegExpNormalChar | | file://:0:0:0:0 | 2 | RegExpConstant,RegExpNormalChar | @@ -48,6 +49,7 @@ term | file://:0:0:0:0 | [[:digit:]] | RegExpCharacterClass | | file://:0:0:0:0 | [[a-f] | RegExpCharacterClass | | file://:0:0:0:0 | [[a-f]A-F] | RegExpSequence | +| file://:0:0:0:0 | [\\0] | RegExpCharacterClass | | file://:0:0:0:0 | [\\cZ] | RegExpCharacterClass | | file://:0:0:0:0 | [\\w] | RegExpCharacterClass | | file://:0:0:0:0 | [\\w]+ | RegExpPlus | @@ -58,6 +60,8 @@ term | file://:0:0:0:0 | [^]] | RegExpCharacterClass | | file://:0:0:0:0 | [a-fA-F0-9_] | RegExpCharacterClass | | file://:0:0:0:0 | [abc] | RegExpCharacterClass | +| file://:0:0:0:0 | \\ | RegExpConstant,RegExpNormalChar | +| file://:0:0:0:0 | \\0 | RegExpConstant,RegExpNormalChar | | file://:0:0:0:0 | \\1 | RegExpBackRef | | file://:0:0:0:0 | \\B | RegExpNonWordBoundary | | file://:0:0:0:0 | \\D | RegExpCharacterClassEscape | @@ -154,6 +158,7 @@ term | file://:0:0:0:0 | o\|b | RegExpAlt | regExpNormalCharValue | file://:0:0:0:0 | 0 | 0 | +| file://:0:0:0:0 | 0 | 0 | | file://:0:0:0:0 | 1 | 1 | | file://:0:0:0:0 | 2 | 2 | | file://:0:0:0:0 | 3 | 3 | @@ -169,6 +174,8 @@ regExpNormalCharValue | file://:0:0:0:0 | F | F | | file://:0:0:0:0 | Z | Z | | file://:0:0:0:0 | [ | [ | +| file://:0:0:0:0 | \\ | \\ | +| file://:0:0:0:0 | \\0 | \\0 | | file://:0:0:0:0 | \\D | D | | file://:0:0:0:0 | \\S | S | | file://:0:0:0:0 | \\W | W | From 53a5473101cd1a6a25400963d57c79c3d748dbd6 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 23 Jul 2026 10:19:10 +0000 Subject: [PATCH 18/26] C++: Implement \0 NUL escape --- .../lib/semmle/code/cpp/regex/internal/ParseRegExp.qll | 5 +++++ cpp/ql/test/library-tests/regex/parse.expected | 9 +++------ cpp/ql/test/library-tests/regex/regexp.expected | 10 ++++------ 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/cpp/ql/lib/semmle/code/cpp/regex/internal/ParseRegExp.qll b/cpp/ql/lib/semmle/code/cpp/regex/internal/ParseRegExp.qll index 191d91990da1..974c57a89084 100644 --- a/cpp/ql/lib/semmle/code/cpp/regex/internal/ParseRegExp.qll +++ b/cpp/ql/lib/semmle/code/cpp/regex/internal/ParseRegExp.qll @@ -347,6 +347,11 @@ abstract class RegExp extends StringLiteral { // control char \cX this.getChar(start + 1) = "c" and end = start + 3 or + // nul escape \0 (when not followed by a digit) + this.getChar(start + 1) = "0" and + end = start + 2 and + not exists(this.getChar(start + 2).toInt()) + or // escape not handled above; update when adding a new case not this.getChar(start + 1) in ["x", "u", "c"] and not exists(this.getChar(start + 1).toInt()) and diff --git a/cpp/ql/test/library-tests/regex/parse.expected b/cpp/ql/test/library-tests/regex/parse.expected index b7d2e50a0628..2ab6e455bd5e 100644 --- a/cpp/ql/test/library-tests/regex/parse.expected +++ b/cpp/ql/test/library-tests/regex/parse.expected @@ -26,11 +26,9 @@ #-----| [RegExpConstant, RegExpNormalChar] b -#-----| [RegExpConstant, RegExpNormalChar] \ +#-----| [RegExpConstant, RegExpEscape] \0 -#-----| [RegExpConstant, RegExpNormalChar] 0 - -#-----| [RegExpConstant, RegExpNormalChar] \0 +#-----| [RegExpConstant, RegExpEscape] \0 #-----| [RegExpConstant, RegExpEscape] \cZ @@ -290,8 +288,7 @@ #-----| 1 -> [RegExpConstant, RegExpNormalChar] 9 #-----| [RegExpCharacterClass] [\0] -#-----| 0 -> [RegExpConstant, RegExpNormalChar] \ -#-----| 1 -> [RegExpConstant, RegExpNormalChar] 0 +#-----| 0 -> [RegExpConstant, RegExpEscape] \0 #-----| [RegExpCharacterClass] [\cZ] #-----| 0 -> [RegExpConstant, RegExpEscape] \cZ diff --git a/cpp/ql/test/library-tests/regex/regexp.expected b/cpp/ql/test/library-tests/regex/regexp.expected index b2c734087d6b..f8bb2b9b726d 100644 --- a/cpp/ql/test/library-tests/regex/regexp.expected +++ b/cpp/ql/test/library-tests/regex/regexp.expected @@ -6,7 +6,6 @@ groupNumber | file://:0:0:0:0 | (o\|b) | 1 | term | file://:0:0:0:0 | 0 | RegExpConstant,RegExpNormalChar | -| file://:0:0:0:0 | 0 | RegExpConstant,RegExpNormalChar | | file://:0:0:0:0 | 0-9 | RegExpCharacterRange | | file://:0:0:0:0 | 1 | RegExpConstant,RegExpNormalChar | | file://:0:0:0:0 | 2 | RegExpConstant,RegExpNormalChar | @@ -60,8 +59,8 @@ term | file://:0:0:0:0 | [^]] | RegExpCharacterClass | | file://:0:0:0:0 | [a-fA-F0-9_] | RegExpCharacterClass | | file://:0:0:0:0 | [abc] | RegExpCharacterClass | -| file://:0:0:0:0 | \\ | RegExpConstant,RegExpNormalChar | -| file://:0:0:0:0 | \\0 | RegExpConstant,RegExpNormalChar | +| file://:0:0:0:0 | \\0 | RegExpConstant,RegExpEscape | +| file://:0:0:0:0 | \\0 | RegExpConstant,RegExpEscape | | file://:0:0:0:0 | \\1 | RegExpBackRef | | file://:0:0:0:0 | \\B | RegExpNonWordBoundary | | file://:0:0:0:0 | \\D | RegExpCharacterClassEscape | @@ -158,7 +157,6 @@ term | file://:0:0:0:0 | o\|b | RegExpAlt | regExpNormalCharValue | file://:0:0:0:0 | 0 | 0 | -| file://:0:0:0:0 | 0 | 0 | | file://:0:0:0:0 | 1 | 1 | | file://:0:0:0:0 | 2 | 2 | | file://:0:0:0:0 | 3 | 3 | @@ -174,8 +172,8 @@ regExpNormalCharValue | file://:0:0:0:0 | F | F | | file://:0:0:0:0 | Z | Z | | file://:0:0:0:0 | [ | [ | -| file://:0:0:0:0 | \\ | \\ | -| file://:0:0:0:0 | \\0 | \\0 | +| file://:0:0:0:0 | \\0 | 0 | +| file://:0:0:0:0 | \\0 | 0 | | file://:0:0:0:0 | \\D | D | | file://:0:0:0:0 | \\S | S | | file://:0:0:0:0 | \\W | W | From ea561e2994746d4e27adb6cfc101bd4854eafefd Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 23 Jul 2026 10:19:40 +0000 Subject: [PATCH 19/26] C++: Add POSIX collating-symbol tests (pre-fix) --- .../test/library-tests/regex/parse.expected | 52 +++++++++++++++++++ cpp/ql/test/library-tests/regex/regexp.cpp | 4 ++ .../test/library-tests/regex/regexp.expected | 31 +++++++++++ 3 files changed, 87 insertions(+) diff --git a/cpp/ql/test/library-tests/regex/parse.expected b/cpp/ql/test/library-tests/regex/parse.expected index 2ab6e455bd5e..420e3f043aec 100644 --- a/cpp/ql/test/library-tests/regex/parse.expected +++ b/cpp/ql/test/library-tests/regex/parse.expected @@ -40,6 +40,32 @@ #-----| [RegExpConstant, RegExpNormalChar] F +#-----| [RegExpConstant, RegExpNormalChar] [ + +#-----| [RegExpConstant, RegExpNormalChar] [ + +#-----| [RegExpConstant, RegExpNormalChar] . + +#-----| [RegExpConstant, RegExpNormalChar] b + +#-----| [RegExpConstant, RegExpNormalChar] . + +#-----| [RegExpConstant, RegExpNormalChar] ]a-f] + +#-----| [RegExpConstant, RegExpNormalChar] [ + +#-----| [RegExpConstant, RegExpNormalChar] . + +#-----| [RegExpConstant, RegExpNormalChar] a + +#-----| [RegExpConstant, RegExpNormalChar] . + +#-----| [RegExpConstant, RegExpNormalChar] ] + +#-----| [RegExpConstant, RegExpNormalChar] A + +#-----| [RegExpConstant, RegExpNormalChar] F + #-----| [RegExpConstant, RegExpNormalChar] a #-----| [RegExpConstant, RegExpNormalChar] f @@ -171,6 +197,14 @@ #-----| 1 -> [RegExpConstant, RegExpEscape] \n #-----| 2 -> [RegExpConstant, RegExpNormalChar] b +#-----| [RegExpSequence] [A-F[[.b.]]a-f] +#-----| 0 -> [RegExpCharacterClass] [A-F[[.b.] +#-----| 1 -> [RegExpConstant, RegExpNormalChar] ]a-f] + +#-----| [RegExpSequence] [[.a.]] +#-----| 0 -> [RegExpCharacterClass] [[.a.] +#-----| 1 -> [RegExpConstant, RegExpNormalChar] ] + #-----| [RegExpSequence] [[:alpha:]][[:digit:]] #-----| 0 -> [RegExpCharacterClass] [[:alpha:]] #-----| 1 -> [RegExpCharacterClass] [[:digit:]] @@ -263,6 +297,10 @@ #-----| 0 -> [RegExpConstant, RegExpNormalChar] A #-----| 1 -> [RegExpConstant, RegExpNormalChar] F +#-----| [RegExpCharacterRange] A-F +#-----| 0 -> [RegExpConstant, RegExpNormalChar] A +#-----| 1 -> [RegExpConstant, RegExpNormalChar] F + #-----| [RegExpCharacterRange] a-f #-----| 0 -> [RegExpConstant, RegExpNormalChar] a #-----| 1 -> [RegExpConstant, RegExpNormalChar] f @@ -293,6 +331,20 @@ #-----| [RegExpCharacterClass] [\cZ] #-----| 0 -> [RegExpConstant, RegExpEscape] \cZ +#-----| [RegExpCharacterClass] [A-F[[.b.] +#-----| 0 -> [RegExpCharacterRange] A-F +#-----| 1 -> [RegExpConstant, RegExpNormalChar] [ +#-----| 2 -> [RegExpConstant, RegExpNormalChar] [ +#-----| 3 -> [RegExpConstant, RegExpNormalChar] . +#-----| 4 -> [RegExpConstant, RegExpNormalChar] b +#-----| 5 -> [RegExpConstant, RegExpNormalChar] . + +#-----| [RegExpCharacterClass] [[.a.] +#-----| 0 -> [RegExpConstant, RegExpNormalChar] [ +#-----| 1 -> [RegExpConstant, RegExpNormalChar] . +#-----| 2 -> [RegExpConstant, RegExpNormalChar] a +#-----| 3 -> [RegExpConstant, RegExpNormalChar] . + #-----| [RegExpCharacterClass] [A-F[:digit:]a-f] #-----| 0 -> [RegExpCharacterRange] A-F diff --git a/cpp/ql/test/library-tests/regex/regexp.cpp b/cpp/ql/test/library-tests/regex/regexp.cpp index 18c3b8d3e484..ebf3b49367f4 100644 --- a/cpp/ql/test/library-tests/regex/regexp.cpp +++ b/cpp/ql/test/library-tests/regex/regexp.cpp @@ -70,6 +70,10 @@ std::regex r_posix2("[[:alpha:][:digit:]]"); // A single character class containing two ranges and one POSIX bracket expression std::regex r_posix3("[A-F[:digit:]a-f]"); +// POSIX collating symbols +std::regex r_posix_coll1("[[.a.]]"); +std::regex r_posix_coll2("[A-F[[.b.]]a-f]"); + // *Not* a POSIX bracket expression; just a regular character class. std::regex r_posix4("[:digit:]"); diff --git a/cpp/ql/test/library-tests/regex/regexp.expected b/cpp/ql/test/library-tests/regex/regexp.expected index f8bb2b9b726d..18707fb6a525 100644 --- a/cpp/ql/test/library-tests/regex/regexp.expected +++ b/cpp/ql/test/library-tests/regex/regexp.expected @@ -23,6 +23,10 @@ term | file://:0:0:0:0 | (foo)*bar | RegExpSequence | | file://:0:0:0:0 | (o\|b) | RegExpGroup | | file://:0:0:0:0 | - | RegExpConstant,RegExpNormalChar | +| file://:0:0:0:0 | . | RegExpConstant,RegExpNormalChar | +| file://:0:0:0:0 | . | RegExpConstant,RegExpNormalChar | +| file://:0:0:0:0 | . | RegExpConstant,RegExpNormalChar | +| file://:0:0:0:0 | . | RegExpConstant,RegExpNormalChar | | file://:0:0:0:0 | . | RegExpDot | | file://:0:0:0:0 | . | RegExpDot | | file://:0:0:0:0 | .* | RegExpStar | @@ -32,16 +36,26 @@ term | file://:0:0:0:0 | A | RegExpConstant,RegExpNormalChar | | file://:0:0:0:0 | A | RegExpConstant,RegExpNormalChar | | file://:0:0:0:0 | A | RegExpConstant,RegExpNormalChar | +| file://:0:0:0:0 | A | RegExpConstant,RegExpNormalChar | +| file://:0:0:0:0 | A-F | RegExpCharacterRange | | file://:0:0:0:0 | A-F | RegExpCharacterRange | | file://:0:0:0:0 | A-F | RegExpCharacterRange | | file://:0:0:0:0 | A-F] | RegExpConstant,RegExpNormalChar | | file://:0:0:0:0 | A-Z | RegExpCharacterRange | | file://:0:0:0:0 | F | RegExpConstant,RegExpNormalChar | | file://:0:0:0:0 | F | RegExpConstant,RegExpNormalChar | +| file://:0:0:0:0 | F | RegExpConstant,RegExpNormalChar | | file://:0:0:0:0 | Z | RegExpConstant,RegExpNormalChar | | file://:0:0:0:0 | [ | RegExpConstant,RegExpNormalChar | +| file://:0:0:0:0 | [ | RegExpConstant,RegExpNormalChar | +| file://:0:0:0:0 | [ | RegExpConstant,RegExpNormalChar | +| file://:0:0:0:0 | [ | RegExpConstant,RegExpNormalChar | | file://:0:0:0:0 | [123] | RegExpCharacterClass | | file://:0:0:0:0 | [A-F[:digit:]a-f] | RegExpCharacterClass | +| file://:0:0:0:0 | [A-F[[.b.] | RegExpCharacterClass | +| file://:0:0:0:0 | [A-F[[.b.]]a-f] | RegExpSequence | +| file://:0:0:0:0 | [[.a.] | RegExpCharacterClass | +| file://:0:0:0:0 | [[.a.]] | RegExpSequence | | file://:0:0:0:0 | [[:alpha:][:digit:]] | RegExpCharacterClass | | file://:0:0:0:0 | [[:alpha:]] | RegExpCharacterClass | | file://:0:0:0:0 | [[:alpha:]][[:digit:]] | RegExpSequence | @@ -91,6 +105,8 @@ term | file://:0:0:0:0 | \| | RegExpConstant,RegExpNormalChar | | file://:0:0:0:0 | ] | RegExpConstant,RegExpNormalChar | | file://:0:0:0:0 | ] | RegExpConstant,RegExpNormalChar | +| file://:0:0:0:0 | ] | RegExpConstant,RegExpNormalChar | +| file://:0:0:0:0 | ]a-f] | RegExpConstant,RegExpNormalChar | | file://:0:0:0:0 | _ | RegExpConstant,RegExpNormalChar | | file://:0:0:0:0 | a | RegExpConstant,RegExpNormalChar | | file://:0:0:0:0 | a | RegExpConstant,RegExpNormalChar | @@ -104,6 +120,7 @@ term | file://:0:0:0:0 | a | RegExpConstant,RegExpNormalChar | | file://:0:0:0:0 | a | RegExpConstant,RegExpNormalChar | | file://:0:0:0:0 | a | RegExpConstant,RegExpNormalChar | +| file://:0:0:0:0 | a | RegExpConstant,RegExpNormalChar | | file://:0:0:0:0 | a* | RegExpStar | | file://:0:0:0:0 | a*b+c?d | RegExpSequence | | file://:0:0:0:0 | a+ | RegExpPlus | @@ -135,6 +152,7 @@ term | file://:0:0:0:0 | b | RegExpConstant,RegExpNormalChar | | file://:0:0:0:0 | b | RegExpConstant,RegExpNormalChar | | file://:0:0:0:0 | b | RegExpConstant,RegExpNormalChar | +| file://:0:0:0:0 | b | RegExpConstant,RegExpNormalChar | | file://:0:0:0:0 | b+ | RegExpPlus | | file://:0:0:0:0 | b+ | RegExpPlus | | file://:0:0:0:0 | bar | RegExpConstant,RegExpNormalChar | @@ -163,15 +181,24 @@ regExpNormalCharValue | file://:0:0:0:0 | 9 | 9 | | file://:0:0:0:0 | !a | !a | | file://:0:0:0:0 | - | - | +| file://:0:0:0:0 | . | . | +| file://:0:0:0:0 | . | . | +| file://:0:0:0:0 | . | . | +| file://:0:0:0:0 | . | . | | file://:0:0:0:0 | : | : | | file://:0:0:0:0 | A | A | | file://:0:0:0:0 | A | A | | file://:0:0:0:0 | A | A | +| file://:0:0:0:0 | A | A | | file://:0:0:0:0 | A-F] | A-F] | | file://:0:0:0:0 | F | F | | file://:0:0:0:0 | F | F | +| file://:0:0:0:0 | F | F | | file://:0:0:0:0 | Z | Z | | file://:0:0:0:0 | [ | [ | +| file://:0:0:0:0 | [ | [ | +| file://:0:0:0:0 | [ | [ | +| file://:0:0:0:0 | [ | [ | | file://:0:0:0:0 | \\0 | 0 | | file://:0:0:0:0 | \\0 | 0 | | file://:0:0:0:0 | \\D | D | @@ -194,6 +221,8 @@ regExpNormalCharValue | file://:0:0:0:0 | \| | \| | | file://:0:0:0:0 | ] | ] | | file://:0:0:0:0 | ] | ] | +| file://:0:0:0:0 | ] | ] | +| file://:0:0:0:0 | ]a-f] | ]a-f] | | file://:0:0:0:0 | _ | _ | | file://:0:0:0:0 | a | a | | file://:0:0:0:0 | a | a | @@ -207,6 +236,7 @@ regExpNormalCharValue | file://:0:0:0:0 | a | a | | file://:0:0:0:0 | a | a | | file://:0:0:0:0 | a | a | +| file://:0:0:0:0 | a | a | | file://:0:0:0:0 | abc | abc | | file://:0:0:0:0 | abc | abc | | file://:0:0:0:0 | abc | abc | @@ -226,6 +256,7 @@ regExpNormalCharValue | file://:0:0:0:0 | b | b | | file://:0:0:0:0 | b | b | | file://:0:0:0:0 | b | b | +| file://:0:0:0:0 | b | b | | file://:0:0:0:0 | bar | bar | | file://:0:0:0:0 | bar | bar | | file://:0:0:0:0 | c | c | From afde8d9fc53ebeb3968e9b49cb38b950086e2f8a Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 23 Jul 2026 10:22:15 +0000 Subject: [PATCH 20/26] C++: Implement POSIX collating symbols --- .../semmle/code/cpp/regex/RegexTreeView.qll | 20 +++++++- .../code/cpp/regex/internal/ParseRegExp.qll | 48 +++++++++++++++++-- .../test/library-tests/regex/parse.expected | 46 +++++------------- .../test/library-tests/regex/regexp.expected | 29 +++-------- 4 files changed, 80 insertions(+), 63 deletions(-) diff --git a/cpp/ql/lib/semmle/code/cpp/regex/RegexTreeView.qll b/cpp/ql/lib/semmle/code/cpp/regex/RegexTreeView.qll index 8eef64c9dc08..cf1b0a02d623 100644 --- a/cpp/ql/lib/semmle/code/cpp/regex/RegexTreeView.qll +++ b/cpp/ql/lib/semmle/code/cpp/regex/RegexTreeView.qll @@ -49,7 +49,11 @@ private newtype TRegExpParent = not re.specialCharacter(start, end, _) } or /** A back reference */ - TRegExpBackRef(RegExp re, int start, int end) { re.backreference(start, end) } + TRegExpBackRef(RegExp re, int start, int end) { re.backreference(start, end) } or + /** A POSIX collating symbol */ + TRegExpPosixCollatingSymbol(RegExp re, int start, int end) { + re.posixStyleCollatingSymbol(start, end, _) + } /** An implementation that satisfies the RegexTreeView signature. */ private module Impl implements RegexTreeViewSig { @@ -137,6 +141,8 @@ private module Impl implements RegexTreeViewSig { exists(seqChild(re, start, end, 1)) // if a sequence does not have more than one element, it should be treated as that element instead. or this = TRegExpSpecialChar(re, start, end) + or + this = TRegExpPosixCollatingSymbol(re, start, end) } /** @@ -177,6 +183,8 @@ private module Impl implements RegexTreeViewSig { result = this.(RegExpSequence).getChild(i) or result = this.(RegExpSpecialChar).getChild(i) + or + result = this.(RegExpPosixCollatingSymbol).getChild(i) } /** @@ -1113,6 +1121,16 @@ private module Impl implements RegexTreeViewSig { override predicate isNullable() { this.getGroup().isNullable() } } + additional class RegExpPosixCollatingSymbol extends RegExpTerm, TRegExpPosixCollatingSymbol { + RegExpPosixCollatingSymbol() { this = TRegExpPosixCollatingSymbol(re, start, end) } + + override RegExpTerm getChild(int i) { none() } + + override string getAPrimaryQlClass() { result = "RegExpPosixCollatingSymbol" } + + string getName() { re.posixStyleCollatingSymbol(start, end, result) } + } + class Top = RegExpParent; /** diff --git a/cpp/ql/lib/semmle/code/cpp/regex/internal/ParseRegExp.qll b/cpp/ql/lib/semmle/code/cpp/regex/internal/ParseRegExp.qll index 974c57a89084..24ba4b47cfbd 100644 --- a/cpp/ql/lib/semmle/code/cpp/regex/internal/ParseRegExp.qll +++ b/cpp/ql/lib/semmle/code/cpp/regex/internal/ParseRegExp.qll @@ -101,7 +101,13 @@ abstract class RegExp extends StringLiteral { // Brackets that art part of POSIX expressions should not count as // char-set delimiters. not exists(int x, int y | - this.posixStyleNamedCharacterProperty(x, y, _) and pos >= x and pos < y + ( + this.posixStyleNamedCharacterProperty(x, y, _) + or + this.posixStyleCollatingSymbol(x, y, _) + ) and + pos >= x and + pos < y ) ) and ( @@ -133,7 +139,13 @@ abstract class RegExp extends StringLiteral { e > innerStart and this.nonEscapedCharAt(e) = "]" and not exists(int x, int y | - this.posixStyleNamedCharacterProperty(x, y, _) and e >= x and e < y + ( + this.posixStyleNamedCharacterProperty(x, y, _) + or + this.posixStyleCollatingSymbol(x, y, _) + ) and + e >= x and + e < y ) | e @@ -162,6 +174,8 @@ abstract class RegExp extends StringLiteral { or this.namedCharacterProperty(start, end, _) or + this.posixStyleCollatingSymbol(start, end, _) + or exists(this.nonEscapedCharAt(start)) and end = start + 1 ) or @@ -171,6 +185,8 @@ abstract class RegExp extends StringLiteral { or this.namedCharacterProperty(start, end, _) or + this.posixStyleCollatingSymbol(start, end, _) + or exists(this.nonEscapedCharAt(start)) and end = start + 1 and not this.getChar(start) = "]" @@ -313,6 +329,21 @@ abstract class RegExp extends StringLiteral { ) } + /** Matches a POSIX collating symbol such as `[.ch.]` within a character class. */ + predicate posixStyleCollatingSymbol(int start, int end, string name) { + this.getChar(start) = "[" and + this.getChar(start + 1) = "." and + end = + min(int e | + e > start and + this.getChar(e - 2) = "." and + this.getChar(e - 1) = "]" + | + e + ) and + name = this.getText().substring(start + 2, end - 2) + } + /** * Holds if the named character property is inverted. Examples for which it holds: * - `\P{Digit}` upper-case P means inverted @@ -371,7 +402,12 @@ abstract class RegExp extends StringLiteral { */ predicate inPosixBracket(int index) { exists(int x, int y | - this.posixStyleNamedCharacterProperty(x, y, _) and index in [x + 1 .. y - 2] + ( + this.posixStyleNamedCharacterProperty(x, y, _) + or + this.posixStyleCollatingSymbol(x, y, _) + ) and + index in [x + 1 .. y - 2] ) } @@ -383,7 +419,11 @@ abstract class RegExp extends StringLiteral { not this.charSet(start, _) and not this.charSet(_, start + 1) and not exists(int x, int y | - this.posixStyleNamedCharacterProperty(x, y, _) and + ( + this.posixStyleNamedCharacterProperty(x, y, _) + or + this.posixStyleCollatingSymbol(x, y, _) + ) and start >= x and end <= y ) and diff --git a/cpp/ql/test/library-tests/regex/parse.expected b/cpp/ql/test/library-tests/regex/parse.expected index 420e3f043aec..e28977182447 100644 --- a/cpp/ql/test/library-tests/regex/parse.expected +++ b/cpp/ql/test/library-tests/regex/parse.expected @@ -42,25 +42,7 @@ #-----| [RegExpConstant, RegExpNormalChar] [ -#-----| [RegExpConstant, RegExpNormalChar] [ - -#-----| [RegExpConstant, RegExpNormalChar] . - -#-----| [RegExpConstant, RegExpNormalChar] b - -#-----| [RegExpConstant, RegExpNormalChar] . - -#-----| [RegExpConstant, RegExpNormalChar] ]a-f] - -#-----| [RegExpConstant, RegExpNormalChar] [ - -#-----| [RegExpConstant, RegExpNormalChar] . - -#-----| [RegExpConstant, RegExpNormalChar] a - -#-----| [RegExpConstant, RegExpNormalChar] . - -#-----| [RegExpConstant, RegExpNormalChar] ] +#-----| [RegExpConstant, RegExpNormalChar] a-f] #-----| [RegExpConstant, RegExpNormalChar] A @@ -198,12 +180,8 @@ #-----| 2 -> [RegExpConstant, RegExpNormalChar] b #-----| [RegExpSequence] [A-F[[.b.]]a-f] -#-----| 0 -> [RegExpCharacterClass] [A-F[[.b.] -#-----| 1 -> [RegExpConstant, RegExpNormalChar] ]a-f] - -#-----| [RegExpSequence] [[.a.]] -#-----| 0 -> [RegExpCharacterClass] [[.a.] -#-----| 1 -> [RegExpConstant, RegExpNormalChar] ] +#-----| 0 -> [RegExpCharacterClass] [A-F[[.b.]] +#-----| 1 -> [RegExpConstant, RegExpNormalChar] a-f] #-----| [RegExpSequence] [[:alpha:]][[:digit:]] #-----| 0 -> [RegExpCharacterClass] [[:alpha:]] @@ -268,6 +246,10 @@ #-----| 2 -> [RegExpOpt] c? #-----| 3 -> [RegExpConstant, RegExpNormalChar] d +#-----| [RegExpPosixCollatingSymbol] [.b.] + +#-----| [RegExpPosixCollatingSymbol] [.a.] + #-----| [RegExpBackRef] \1 #-----| [RegExpSpecialChar] \b @@ -331,19 +313,13 @@ #-----| [RegExpCharacterClass] [\cZ] #-----| 0 -> [RegExpConstant, RegExpEscape] \cZ -#-----| [RegExpCharacterClass] [A-F[[.b.] +#-----| [RegExpCharacterClass] [A-F[[.b.]] #-----| 0 -> [RegExpCharacterRange] A-F #-----| 1 -> [RegExpConstant, RegExpNormalChar] [ -#-----| 2 -> [RegExpConstant, RegExpNormalChar] [ -#-----| 3 -> [RegExpConstant, RegExpNormalChar] . -#-----| 4 -> [RegExpConstant, RegExpNormalChar] b -#-----| 5 -> [RegExpConstant, RegExpNormalChar] . +#-----| 2 -> [RegExpPosixCollatingSymbol] [.b.] -#-----| [RegExpCharacterClass] [[.a.] -#-----| 0 -> [RegExpConstant, RegExpNormalChar] [ -#-----| 1 -> [RegExpConstant, RegExpNormalChar] . -#-----| 2 -> [RegExpConstant, RegExpNormalChar] a -#-----| 3 -> [RegExpConstant, RegExpNormalChar] . +#-----| [RegExpCharacterClass] [[.a.]] +#-----| 0 -> [RegExpPosixCollatingSymbol] [.a.] #-----| [RegExpCharacterClass] [A-F[:digit:]a-f] #-----| 0 -> [RegExpCharacterRange] A-F diff --git a/cpp/ql/test/library-tests/regex/regexp.expected b/cpp/ql/test/library-tests/regex/regexp.expected index 18707fb6a525..9c7f8506d323 100644 --- a/cpp/ql/test/library-tests/regex/regexp.expected +++ b/cpp/ql/test/library-tests/regex/regexp.expected @@ -23,10 +23,6 @@ term | file://:0:0:0:0 | (foo)*bar | RegExpSequence | | file://:0:0:0:0 | (o\|b) | RegExpGroup | | file://:0:0:0:0 | - | RegExpConstant,RegExpNormalChar | -| file://:0:0:0:0 | . | RegExpConstant,RegExpNormalChar | -| file://:0:0:0:0 | . | RegExpConstant,RegExpNormalChar | -| file://:0:0:0:0 | . | RegExpConstant,RegExpNormalChar | -| file://:0:0:0:0 | . | RegExpConstant,RegExpNormalChar | | file://:0:0:0:0 | . | RegExpDot | | file://:0:0:0:0 | . | RegExpDot | | file://:0:0:0:0 | .* | RegExpStar | @@ -48,14 +44,13 @@ term | file://:0:0:0:0 | Z | RegExpConstant,RegExpNormalChar | | file://:0:0:0:0 | [ | RegExpConstant,RegExpNormalChar | | file://:0:0:0:0 | [ | RegExpConstant,RegExpNormalChar | -| file://:0:0:0:0 | [ | RegExpConstant,RegExpNormalChar | -| file://:0:0:0:0 | [ | RegExpConstant,RegExpNormalChar | | file://:0:0:0:0 | [123] | RegExpCharacterClass | +| file://:0:0:0:0 | [.a.] | RegExpPosixCollatingSymbol | +| file://:0:0:0:0 | [.b.] | RegExpPosixCollatingSymbol | | file://:0:0:0:0 | [A-F[:digit:]a-f] | RegExpCharacterClass | -| file://:0:0:0:0 | [A-F[[.b.] | RegExpCharacterClass | +| file://:0:0:0:0 | [A-F[[.b.]] | RegExpCharacterClass | | file://:0:0:0:0 | [A-F[[.b.]]a-f] | RegExpSequence | -| file://:0:0:0:0 | [[.a.] | RegExpCharacterClass | -| file://:0:0:0:0 | [[.a.]] | RegExpSequence | +| file://:0:0:0:0 | [[.a.]] | RegExpCharacterClass | | file://:0:0:0:0 | [[:alpha:][:digit:]] | RegExpCharacterClass | | file://:0:0:0:0 | [[:alpha:]] | RegExpCharacterClass | | file://:0:0:0:0 | [[:alpha:]][[:digit:]] | RegExpSequence | @@ -105,8 +100,6 @@ term | file://:0:0:0:0 | \| | RegExpConstant,RegExpNormalChar | | file://:0:0:0:0 | ] | RegExpConstant,RegExpNormalChar | | file://:0:0:0:0 | ] | RegExpConstant,RegExpNormalChar | -| file://:0:0:0:0 | ] | RegExpConstant,RegExpNormalChar | -| file://:0:0:0:0 | ]a-f] | RegExpConstant,RegExpNormalChar | | file://:0:0:0:0 | _ | RegExpConstant,RegExpNormalChar | | file://:0:0:0:0 | a | RegExpConstant,RegExpNormalChar | | file://:0:0:0:0 | a | RegExpConstant,RegExpNormalChar | @@ -120,13 +113,13 @@ term | file://:0:0:0:0 | a | RegExpConstant,RegExpNormalChar | | file://:0:0:0:0 | a | RegExpConstant,RegExpNormalChar | | file://:0:0:0:0 | a | RegExpConstant,RegExpNormalChar | -| file://:0:0:0:0 | a | RegExpConstant,RegExpNormalChar | | file://:0:0:0:0 | a* | RegExpStar | | file://:0:0:0:0 | a*b+c?d | RegExpSequence | | file://:0:0:0:0 | a+ | RegExpPlus | | file://:0:0:0:0 | a-f | RegExpCharacterRange | | file://:0:0:0:0 | a-f | RegExpCharacterRange | | file://:0:0:0:0 | a-f | RegExpCharacterRange | +| file://:0:0:0:0 | a-f] | RegExpConstant,RegExpNormalChar | | file://:0:0:0:0 | a\\nb | RegExpSequence | | file://:0:0:0:0 | a\|b\|cd | RegExpAlt | | file://:0:0:0:0 | abc | RegExpConstant,RegExpNormalChar | @@ -152,7 +145,6 @@ term | file://:0:0:0:0 | b | RegExpConstant,RegExpNormalChar | | file://:0:0:0:0 | b | RegExpConstant,RegExpNormalChar | | file://:0:0:0:0 | b | RegExpConstant,RegExpNormalChar | -| file://:0:0:0:0 | b | RegExpConstant,RegExpNormalChar | | file://:0:0:0:0 | b+ | RegExpPlus | | file://:0:0:0:0 | b+ | RegExpPlus | | file://:0:0:0:0 | bar | RegExpConstant,RegExpNormalChar | @@ -181,10 +173,6 @@ regExpNormalCharValue | file://:0:0:0:0 | 9 | 9 | | file://:0:0:0:0 | !a | !a | | file://:0:0:0:0 | - | - | -| file://:0:0:0:0 | . | . | -| file://:0:0:0:0 | . | . | -| file://:0:0:0:0 | . | . | -| file://:0:0:0:0 | . | . | | file://:0:0:0:0 | : | : | | file://:0:0:0:0 | A | A | | file://:0:0:0:0 | A | A | @@ -197,8 +185,6 @@ regExpNormalCharValue | file://:0:0:0:0 | Z | Z | | file://:0:0:0:0 | [ | [ | | file://:0:0:0:0 | [ | [ | -| file://:0:0:0:0 | [ | [ | -| file://:0:0:0:0 | [ | [ | | file://:0:0:0:0 | \\0 | 0 | | file://:0:0:0:0 | \\0 | 0 | | file://:0:0:0:0 | \\D | D | @@ -221,8 +207,6 @@ regExpNormalCharValue | file://:0:0:0:0 | \| | \| | | file://:0:0:0:0 | ] | ] | | file://:0:0:0:0 | ] | ] | -| file://:0:0:0:0 | ] | ] | -| file://:0:0:0:0 | ]a-f] | ]a-f] | | file://:0:0:0:0 | _ | _ | | file://:0:0:0:0 | a | a | | file://:0:0:0:0 | a | a | @@ -236,7 +220,7 @@ regExpNormalCharValue | file://:0:0:0:0 | a | a | | file://:0:0:0:0 | a | a | | file://:0:0:0:0 | a | a | -| file://:0:0:0:0 | a | a | +| file://:0:0:0:0 | a-f] | a-f] | | file://:0:0:0:0 | abc | abc | | file://:0:0:0:0 | abc | abc | | file://:0:0:0:0 | abc | abc | @@ -256,7 +240,6 @@ regExpNormalCharValue | file://:0:0:0:0 | b | b | | file://:0:0:0:0 | b | b | | file://:0:0:0:0 | b | b | -| file://:0:0:0:0 | b | b | | file://:0:0:0:0 | bar | bar | | file://:0:0:0:0 | bar | bar | | file://:0:0:0:0 | c | c | From 545d87a1787c5aa05d64bf57960b2c56935350fe Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 23 Jul 2026 10:22:51 +0000 Subject: [PATCH 21/26] C++: Add POSIX equivalence-class tests (pre-fix) --- .../test/library-tests/regex/parse.expected | 52 +++++++++++++++++++ cpp/ql/test/library-tests/regex/regexp.cpp | 4 ++ .../test/library-tests/regex/regexp.expected | 31 +++++++++++ 3 files changed, 87 insertions(+) diff --git a/cpp/ql/test/library-tests/regex/parse.expected b/cpp/ql/test/library-tests/regex/parse.expected index e28977182447..32bf025e6d76 100644 --- a/cpp/ql/test/library-tests/regex/parse.expected +++ b/cpp/ql/test/library-tests/regex/parse.expected @@ -42,6 +42,32 @@ #-----| [RegExpConstant, RegExpNormalChar] [ +#-----| [RegExpConstant, RegExpNormalChar] [ + +#-----| [RegExpConstant, RegExpNormalChar] = + +#-----| [RegExpConstant, RegExpNormalChar] b + +#-----| [RegExpConstant, RegExpNormalChar] = + +#-----| [RegExpConstant, RegExpNormalChar] ]a-f] + +#-----| [RegExpConstant, RegExpNormalChar] [ + +#-----| [RegExpConstant, RegExpNormalChar] = + +#-----| [RegExpConstant, RegExpNormalChar] a + +#-----| [RegExpConstant, RegExpNormalChar] = + +#-----| [RegExpConstant, RegExpNormalChar] ] + +#-----| [RegExpConstant, RegExpNormalChar] A + +#-----| [RegExpConstant, RegExpNormalChar] F + +#-----| [RegExpConstant, RegExpNormalChar] [ + #-----| [RegExpConstant, RegExpNormalChar] a-f] #-----| [RegExpConstant, RegExpNormalChar] A @@ -179,6 +205,14 @@ #-----| 1 -> [RegExpConstant, RegExpEscape] \n #-----| 2 -> [RegExpConstant, RegExpNormalChar] b +#-----| [RegExpSequence] [A-F[[=b=]]a-f] +#-----| 0 -> [RegExpCharacterClass] [A-F[[=b=] +#-----| 1 -> [RegExpConstant, RegExpNormalChar] ]a-f] + +#-----| [RegExpSequence] [[=a=]] +#-----| 0 -> [RegExpCharacterClass] [[=a=] +#-----| 1 -> [RegExpConstant, RegExpNormalChar] ] + #-----| [RegExpSequence] [A-F[[.b.]]a-f] #-----| 0 -> [RegExpCharacterClass] [A-F[[.b.]] #-----| 1 -> [RegExpConstant, RegExpNormalChar] a-f] @@ -283,6 +317,10 @@ #-----| 0 -> [RegExpConstant, RegExpNormalChar] A #-----| 1 -> [RegExpConstant, RegExpNormalChar] F +#-----| [RegExpCharacterRange] A-F +#-----| 0 -> [RegExpConstant, RegExpNormalChar] A +#-----| 1 -> [RegExpConstant, RegExpNormalChar] F + #-----| [RegExpCharacterRange] a-f #-----| 0 -> [RegExpConstant, RegExpNormalChar] a #-----| 1 -> [RegExpConstant, RegExpNormalChar] f @@ -313,6 +351,20 @@ #-----| [RegExpCharacterClass] [\cZ] #-----| 0 -> [RegExpConstant, RegExpEscape] \cZ +#-----| [RegExpCharacterClass] [A-F[[=b=] +#-----| 0 -> [RegExpCharacterRange] A-F +#-----| 1 -> [RegExpConstant, RegExpNormalChar] [ +#-----| 2 -> [RegExpConstant, RegExpNormalChar] [ +#-----| 3 -> [RegExpConstant, RegExpNormalChar] = +#-----| 4 -> [RegExpConstant, RegExpNormalChar] b +#-----| 5 -> [RegExpConstant, RegExpNormalChar] = + +#-----| [RegExpCharacterClass] [[=a=] +#-----| 0 -> [RegExpConstant, RegExpNormalChar] [ +#-----| 1 -> [RegExpConstant, RegExpNormalChar] = +#-----| 2 -> [RegExpConstant, RegExpNormalChar] a +#-----| 3 -> [RegExpConstant, RegExpNormalChar] = + #-----| [RegExpCharacterClass] [A-F[[.b.]] #-----| 0 -> [RegExpCharacterRange] A-F #-----| 1 -> [RegExpConstant, RegExpNormalChar] [ diff --git a/cpp/ql/test/library-tests/regex/regexp.cpp b/cpp/ql/test/library-tests/regex/regexp.cpp index ebf3b49367f4..8806b6548077 100644 --- a/cpp/ql/test/library-tests/regex/regexp.cpp +++ b/cpp/ql/test/library-tests/regex/regexp.cpp @@ -74,6 +74,10 @@ std::regex r_posix3("[A-F[:digit:]a-f]"); std::regex r_posix_coll1("[[.a.]]"); std::regex r_posix_coll2("[A-F[[.b.]]a-f]"); +// POSIX equivalence classes +std::regex r_posix_equiv1("[[=a=]]"); +std::regex r_posix_equiv2("[A-F[[=b=]]a-f]"); + // *Not* a POSIX bracket expression; just a regular character class. std::regex r_posix4("[:digit:]"); diff --git a/cpp/ql/test/library-tests/regex/regexp.expected b/cpp/ql/test/library-tests/regex/regexp.expected index 9c7f8506d323..b8c4976a0dff 100644 --- a/cpp/ql/test/library-tests/regex/regexp.expected +++ b/cpp/ql/test/library-tests/regex/regexp.expected @@ -29,10 +29,16 @@ term | file://:0:0:0:0 | .* | RegExpStar | | file://:0:0:0:0 | : | RegExpConstant,RegExpNormalChar | | file://:0:0:0:0 | :+ | RegExpPlus | +| file://:0:0:0:0 | = | RegExpConstant,RegExpNormalChar | +| file://:0:0:0:0 | = | RegExpConstant,RegExpNormalChar | +| file://:0:0:0:0 | = | RegExpConstant,RegExpNormalChar | +| file://:0:0:0:0 | = | RegExpConstant,RegExpNormalChar | | file://:0:0:0:0 | A | RegExpConstant,RegExpNormalChar | | file://:0:0:0:0 | A | RegExpConstant,RegExpNormalChar | | file://:0:0:0:0 | A | RegExpConstant,RegExpNormalChar | | file://:0:0:0:0 | A | RegExpConstant,RegExpNormalChar | +| file://:0:0:0:0 | A | RegExpConstant,RegExpNormalChar | +| file://:0:0:0:0 | A-F | RegExpCharacterRange | | file://:0:0:0:0 | A-F | RegExpCharacterRange | | file://:0:0:0:0 | A-F | RegExpCharacterRange | | file://:0:0:0:0 | A-F | RegExpCharacterRange | @@ -41,20 +47,28 @@ term | file://:0:0:0:0 | F | RegExpConstant,RegExpNormalChar | | file://:0:0:0:0 | F | RegExpConstant,RegExpNormalChar | | file://:0:0:0:0 | F | RegExpConstant,RegExpNormalChar | +| file://:0:0:0:0 | F | RegExpConstant,RegExpNormalChar | | file://:0:0:0:0 | Z | RegExpConstant,RegExpNormalChar | | file://:0:0:0:0 | [ | RegExpConstant,RegExpNormalChar | | file://:0:0:0:0 | [ | RegExpConstant,RegExpNormalChar | +| file://:0:0:0:0 | [ | RegExpConstant,RegExpNormalChar | +| file://:0:0:0:0 | [ | RegExpConstant,RegExpNormalChar | +| file://:0:0:0:0 | [ | RegExpConstant,RegExpNormalChar | | file://:0:0:0:0 | [123] | RegExpCharacterClass | | file://:0:0:0:0 | [.a.] | RegExpPosixCollatingSymbol | | file://:0:0:0:0 | [.b.] | RegExpPosixCollatingSymbol | | file://:0:0:0:0 | [A-F[:digit:]a-f] | RegExpCharacterClass | | file://:0:0:0:0 | [A-F[[.b.]] | RegExpCharacterClass | | file://:0:0:0:0 | [A-F[[.b.]]a-f] | RegExpSequence | +| file://:0:0:0:0 | [A-F[[=b=] | RegExpCharacterClass | +| file://:0:0:0:0 | [A-F[[=b=]]a-f] | RegExpSequence | | file://:0:0:0:0 | [[.a.]] | RegExpCharacterClass | | file://:0:0:0:0 | [[:alpha:][:digit:]] | RegExpCharacterClass | | file://:0:0:0:0 | [[:alpha:]] | RegExpCharacterClass | | file://:0:0:0:0 | [[:alpha:]][[:digit:]] | RegExpSequence | | file://:0:0:0:0 | [[:digit:]] | RegExpCharacterClass | +| file://:0:0:0:0 | [[=a=] | RegExpCharacterClass | +| file://:0:0:0:0 | [[=a=]] | RegExpSequence | | file://:0:0:0:0 | [[a-f] | RegExpCharacterClass | | file://:0:0:0:0 | [[a-f]A-F] | RegExpSequence | | file://:0:0:0:0 | [\\0] | RegExpCharacterClass | @@ -100,6 +114,8 @@ term | file://:0:0:0:0 | \| | RegExpConstant,RegExpNormalChar | | file://:0:0:0:0 | ] | RegExpConstant,RegExpNormalChar | | file://:0:0:0:0 | ] | RegExpConstant,RegExpNormalChar | +| file://:0:0:0:0 | ] | RegExpConstant,RegExpNormalChar | +| file://:0:0:0:0 | ]a-f] | RegExpConstant,RegExpNormalChar | | file://:0:0:0:0 | _ | RegExpConstant,RegExpNormalChar | | file://:0:0:0:0 | a | RegExpConstant,RegExpNormalChar | | file://:0:0:0:0 | a | RegExpConstant,RegExpNormalChar | @@ -113,6 +129,7 @@ term | file://:0:0:0:0 | a | RegExpConstant,RegExpNormalChar | | file://:0:0:0:0 | a | RegExpConstant,RegExpNormalChar | | file://:0:0:0:0 | a | RegExpConstant,RegExpNormalChar | +| file://:0:0:0:0 | a | RegExpConstant,RegExpNormalChar | | file://:0:0:0:0 | a* | RegExpStar | | file://:0:0:0:0 | a*b+c?d | RegExpSequence | | file://:0:0:0:0 | a+ | RegExpPlus | @@ -145,6 +162,7 @@ term | file://:0:0:0:0 | b | RegExpConstant,RegExpNormalChar | | file://:0:0:0:0 | b | RegExpConstant,RegExpNormalChar | | file://:0:0:0:0 | b | RegExpConstant,RegExpNormalChar | +| file://:0:0:0:0 | b | RegExpConstant,RegExpNormalChar | | file://:0:0:0:0 | b+ | RegExpPlus | | file://:0:0:0:0 | b+ | RegExpPlus | | file://:0:0:0:0 | bar | RegExpConstant,RegExpNormalChar | @@ -174,6 +192,11 @@ regExpNormalCharValue | file://:0:0:0:0 | !a | !a | | file://:0:0:0:0 | - | - | | file://:0:0:0:0 | : | : | +| file://:0:0:0:0 | = | = | +| file://:0:0:0:0 | = | = | +| file://:0:0:0:0 | = | = | +| file://:0:0:0:0 | = | = | +| file://:0:0:0:0 | A | A | | file://:0:0:0:0 | A | A | | file://:0:0:0:0 | A | A | | file://:0:0:0:0 | A | A | @@ -182,9 +205,13 @@ regExpNormalCharValue | file://:0:0:0:0 | F | F | | file://:0:0:0:0 | F | F | | file://:0:0:0:0 | F | F | +| file://:0:0:0:0 | F | F | | file://:0:0:0:0 | Z | Z | | file://:0:0:0:0 | [ | [ | | file://:0:0:0:0 | [ | [ | +| file://:0:0:0:0 | [ | [ | +| file://:0:0:0:0 | [ | [ | +| file://:0:0:0:0 | [ | [ | | file://:0:0:0:0 | \\0 | 0 | | file://:0:0:0:0 | \\0 | 0 | | file://:0:0:0:0 | \\D | D | @@ -207,6 +234,8 @@ regExpNormalCharValue | file://:0:0:0:0 | \| | \| | | file://:0:0:0:0 | ] | ] | | file://:0:0:0:0 | ] | ] | +| file://:0:0:0:0 | ] | ] | +| file://:0:0:0:0 | ]a-f] | ]a-f] | | file://:0:0:0:0 | _ | _ | | file://:0:0:0:0 | a | a | | file://:0:0:0:0 | a | a | @@ -220,6 +249,7 @@ regExpNormalCharValue | file://:0:0:0:0 | a | a | | file://:0:0:0:0 | a | a | | file://:0:0:0:0 | a | a | +| file://:0:0:0:0 | a | a | | file://:0:0:0:0 | a-f] | a-f] | | file://:0:0:0:0 | abc | abc | | file://:0:0:0:0 | abc | abc | @@ -240,6 +270,7 @@ regExpNormalCharValue | file://:0:0:0:0 | b | b | | file://:0:0:0:0 | b | b | | file://:0:0:0:0 | b | b | +| file://:0:0:0:0 | b | b | | file://:0:0:0:0 | bar | bar | | file://:0:0:0:0 | bar | bar | | file://:0:0:0:0 | c | c | From 12dc4b250f559424efa39a9377f15cd7ae36b214 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 23 Jul 2026 10:24:06 +0000 Subject: [PATCH 22/26] C++: Implement POSIX equivalence classes --- .../semmle/code/cpp/regex/RegexTreeView.qll | 18 ++++++++ .../code/cpp/regex/internal/ParseRegExp.qll | 27 +++++++++++ .../test/library-tests/regex/parse.expected | 46 +++++-------------- .../test/library-tests/regex/regexp.expected | 29 +++--------- 4 files changed, 62 insertions(+), 58 deletions(-) diff --git a/cpp/ql/lib/semmle/code/cpp/regex/RegexTreeView.qll b/cpp/ql/lib/semmle/code/cpp/regex/RegexTreeView.qll index cf1b0a02d623..7097025c6cb6 100644 --- a/cpp/ql/lib/semmle/code/cpp/regex/RegexTreeView.qll +++ b/cpp/ql/lib/semmle/code/cpp/regex/RegexTreeView.qll @@ -53,6 +53,10 @@ private newtype TRegExpParent = /** A POSIX collating symbol */ TRegExpPosixCollatingSymbol(RegExp re, int start, int end) { re.posixStyleCollatingSymbol(start, end, _) + } or + /** A POSIX equivalence class */ + TRegExpPosixEquivalenceClass(RegExp re, int start, int end) { + re.posixStyleEquivalenceClass(start, end, _) } /** An implementation that satisfies the RegexTreeView signature. */ @@ -143,6 +147,8 @@ private module Impl implements RegexTreeViewSig { this = TRegExpSpecialChar(re, start, end) or this = TRegExpPosixCollatingSymbol(re, start, end) + or + this = TRegExpPosixEquivalenceClass(re, start, end) } /** @@ -185,6 +191,8 @@ private module Impl implements RegexTreeViewSig { result = this.(RegExpSpecialChar).getChild(i) or result = this.(RegExpPosixCollatingSymbol).getChild(i) + or + result = this.(RegExpPosixEquivalenceClass).getChild(i) } /** @@ -1131,6 +1139,16 @@ private module Impl implements RegexTreeViewSig { string getName() { re.posixStyleCollatingSymbol(start, end, result) } } + additional class RegExpPosixEquivalenceClass extends RegExpTerm, TRegExpPosixEquivalenceClass { + RegExpPosixEquivalenceClass() { this = TRegExpPosixEquivalenceClass(re, start, end) } + + override RegExpTerm getChild(int i) { none() } + + override string getAPrimaryQlClass() { result = "RegExpPosixEquivalenceClass" } + + string getName() { re.posixStyleEquivalenceClass(start, end, result) } + } + class Top = RegExpParent; /** diff --git a/cpp/ql/lib/semmle/code/cpp/regex/internal/ParseRegExp.qll b/cpp/ql/lib/semmle/code/cpp/regex/internal/ParseRegExp.qll index 24ba4b47cfbd..739b2c884810 100644 --- a/cpp/ql/lib/semmle/code/cpp/regex/internal/ParseRegExp.qll +++ b/cpp/ql/lib/semmle/code/cpp/regex/internal/ParseRegExp.qll @@ -105,6 +105,8 @@ abstract class RegExp extends StringLiteral { this.posixStyleNamedCharacterProperty(x, y, _) or this.posixStyleCollatingSymbol(x, y, _) + or + this.posixStyleEquivalenceClass(x, y, _) ) and pos >= x and pos < y @@ -143,6 +145,8 @@ abstract class RegExp extends StringLiteral { this.posixStyleNamedCharacterProperty(x, y, _) or this.posixStyleCollatingSymbol(x, y, _) + or + this.posixStyleEquivalenceClass(x, y, _) ) and e >= x and e < y @@ -176,6 +180,8 @@ abstract class RegExp extends StringLiteral { or this.posixStyleCollatingSymbol(start, end, _) or + this.posixStyleEquivalenceClass(start, end, _) + or exists(this.nonEscapedCharAt(start)) and end = start + 1 ) or @@ -187,6 +193,8 @@ abstract class RegExp extends StringLiteral { or this.posixStyleCollatingSymbol(start, end, _) or + this.posixStyleEquivalenceClass(start, end, _) + or exists(this.nonEscapedCharAt(start)) and end = start + 1 and not this.getChar(start) = "]" @@ -344,6 +352,21 @@ abstract class RegExp extends StringLiteral { name = this.getText().substring(start + 2, end - 2) } + /** Matches a POSIX equivalence class such as `[=a=]` within a character class. */ + predicate posixStyleEquivalenceClass(int start, int end, string name) { + this.getChar(start) = "[" and + this.getChar(start + 1) = "=" and + end = + min(int e | + e > start and + this.getChar(e - 2) = "=" and + this.getChar(e - 1) = "]" + | + e + ) and + name = this.getText().substring(start + 2, end - 2) + } + /** * Holds if the named character property is inverted. Examples for which it holds: * - `\P{Digit}` upper-case P means inverted @@ -406,6 +429,8 @@ abstract class RegExp extends StringLiteral { this.posixStyleNamedCharacterProperty(x, y, _) or this.posixStyleCollatingSymbol(x, y, _) + or + this.posixStyleEquivalenceClass(x, y, _) ) and index in [x + 1 .. y - 2] ) @@ -423,6 +448,8 @@ abstract class RegExp extends StringLiteral { this.posixStyleNamedCharacterProperty(x, y, _) or this.posixStyleCollatingSymbol(x, y, _) + or + this.posixStyleEquivalenceClass(x, y, _) ) and start >= x and end <= y diff --git a/cpp/ql/test/library-tests/regex/parse.expected b/cpp/ql/test/library-tests/regex/parse.expected index 32bf025e6d76..82c57962c2f2 100644 --- a/cpp/ql/test/library-tests/regex/parse.expected +++ b/cpp/ql/test/library-tests/regex/parse.expected @@ -42,25 +42,7 @@ #-----| [RegExpConstant, RegExpNormalChar] [ -#-----| [RegExpConstant, RegExpNormalChar] [ - -#-----| [RegExpConstant, RegExpNormalChar] = - -#-----| [RegExpConstant, RegExpNormalChar] b - -#-----| [RegExpConstant, RegExpNormalChar] = - -#-----| [RegExpConstant, RegExpNormalChar] ]a-f] - -#-----| [RegExpConstant, RegExpNormalChar] [ - -#-----| [RegExpConstant, RegExpNormalChar] = - -#-----| [RegExpConstant, RegExpNormalChar] a - -#-----| [RegExpConstant, RegExpNormalChar] = - -#-----| [RegExpConstant, RegExpNormalChar] ] +#-----| [RegExpConstant, RegExpNormalChar] a-f] #-----| [RegExpConstant, RegExpNormalChar] A @@ -206,12 +188,8 @@ #-----| 2 -> [RegExpConstant, RegExpNormalChar] b #-----| [RegExpSequence] [A-F[[=b=]]a-f] -#-----| 0 -> [RegExpCharacterClass] [A-F[[=b=] -#-----| 1 -> [RegExpConstant, RegExpNormalChar] ]a-f] - -#-----| [RegExpSequence] [[=a=]] -#-----| 0 -> [RegExpCharacterClass] [[=a=] -#-----| 1 -> [RegExpConstant, RegExpNormalChar] ] +#-----| 0 -> [RegExpCharacterClass] [A-F[[=b=]] +#-----| 1 -> [RegExpConstant, RegExpNormalChar] a-f] #-----| [RegExpSequence] [A-F[[.b.]]a-f] #-----| 0 -> [RegExpCharacterClass] [A-F[[.b.]] @@ -280,6 +258,10 @@ #-----| 2 -> [RegExpOpt] c? #-----| 3 -> [RegExpConstant, RegExpNormalChar] d +#-----| [RegExpPosixEquivalenceClass] [=b=] + +#-----| [RegExpPosixEquivalenceClass] [=a=] + #-----| [RegExpPosixCollatingSymbol] [.b.] #-----| [RegExpPosixCollatingSymbol] [.a.] @@ -351,19 +333,13 @@ #-----| [RegExpCharacterClass] [\cZ] #-----| 0 -> [RegExpConstant, RegExpEscape] \cZ -#-----| [RegExpCharacterClass] [A-F[[=b=] +#-----| [RegExpCharacterClass] [A-F[[=b=]] #-----| 0 -> [RegExpCharacterRange] A-F #-----| 1 -> [RegExpConstant, RegExpNormalChar] [ -#-----| 2 -> [RegExpConstant, RegExpNormalChar] [ -#-----| 3 -> [RegExpConstant, RegExpNormalChar] = -#-----| 4 -> [RegExpConstant, RegExpNormalChar] b -#-----| 5 -> [RegExpConstant, RegExpNormalChar] = +#-----| 2 -> [RegExpPosixEquivalenceClass] [=b=] -#-----| [RegExpCharacterClass] [[=a=] -#-----| 0 -> [RegExpConstant, RegExpNormalChar] [ -#-----| 1 -> [RegExpConstant, RegExpNormalChar] = -#-----| 2 -> [RegExpConstant, RegExpNormalChar] a -#-----| 3 -> [RegExpConstant, RegExpNormalChar] = +#-----| [RegExpCharacterClass] [[=a=]] +#-----| 0 -> [RegExpPosixEquivalenceClass] [=a=] #-----| [RegExpCharacterClass] [A-F[[.b.]] #-----| 0 -> [RegExpCharacterRange] A-F diff --git a/cpp/ql/test/library-tests/regex/regexp.expected b/cpp/ql/test/library-tests/regex/regexp.expected index b8c4976a0dff..ac7aa2b58d6b 100644 --- a/cpp/ql/test/library-tests/regex/regexp.expected +++ b/cpp/ql/test/library-tests/regex/regexp.expected @@ -29,10 +29,6 @@ term | file://:0:0:0:0 | .* | RegExpStar | | file://:0:0:0:0 | : | RegExpConstant,RegExpNormalChar | | file://:0:0:0:0 | :+ | RegExpPlus | -| file://:0:0:0:0 | = | RegExpConstant,RegExpNormalChar | -| file://:0:0:0:0 | = | RegExpConstant,RegExpNormalChar | -| file://:0:0:0:0 | = | RegExpConstant,RegExpNormalChar | -| file://:0:0:0:0 | = | RegExpConstant,RegExpNormalChar | | file://:0:0:0:0 | A | RegExpConstant,RegExpNormalChar | | file://:0:0:0:0 | A | RegExpConstant,RegExpNormalChar | | file://:0:0:0:0 | A | RegExpConstant,RegExpNormalChar | @@ -52,23 +48,22 @@ term | file://:0:0:0:0 | [ | RegExpConstant,RegExpNormalChar | | file://:0:0:0:0 | [ | RegExpConstant,RegExpNormalChar | | file://:0:0:0:0 | [ | RegExpConstant,RegExpNormalChar | -| file://:0:0:0:0 | [ | RegExpConstant,RegExpNormalChar | -| file://:0:0:0:0 | [ | RegExpConstant,RegExpNormalChar | | file://:0:0:0:0 | [123] | RegExpCharacterClass | | file://:0:0:0:0 | [.a.] | RegExpPosixCollatingSymbol | | file://:0:0:0:0 | [.b.] | RegExpPosixCollatingSymbol | +| file://:0:0:0:0 | [=a=] | RegExpPosixEquivalenceClass | +| file://:0:0:0:0 | [=b=] | RegExpPosixEquivalenceClass | | file://:0:0:0:0 | [A-F[:digit:]a-f] | RegExpCharacterClass | | file://:0:0:0:0 | [A-F[[.b.]] | RegExpCharacterClass | | file://:0:0:0:0 | [A-F[[.b.]]a-f] | RegExpSequence | -| file://:0:0:0:0 | [A-F[[=b=] | RegExpCharacterClass | +| file://:0:0:0:0 | [A-F[[=b=]] | RegExpCharacterClass | | file://:0:0:0:0 | [A-F[[=b=]]a-f] | RegExpSequence | | file://:0:0:0:0 | [[.a.]] | RegExpCharacterClass | | file://:0:0:0:0 | [[:alpha:][:digit:]] | RegExpCharacterClass | | file://:0:0:0:0 | [[:alpha:]] | RegExpCharacterClass | | file://:0:0:0:0 | [[:alpha:]][[:digit:]] | RegExpSequence | | file://:0:0:0:0 | [[:digit:]] | RegExpCharacterClass | -| file://:0:0:0:0 | [[=a=] | RegExpCharacterClass | -| file://:0:0:0:0 | [[=a=]] | RegExpSequence | +| file://:0:0:0:0 | [[=a=]] | RegExpCharacterClass | | file://:0:0:0:0 | [[a-f] | RegExpCharacterClass | | file://:0:0:0:0 | [[a-f]A-F] | RegExpSequence | | file://:0:0:0:0 | [\\0] | RegExpCharacterClass | @@ -114,8 +109,6 @@ term | file://:0:0:0:0 | \| | RegExpConstant,RegExpNormalChar | | file://:0:0:0:0 | ] | RegExpConstant,RegExpNormalChar | | file://:0:0:0:0 | ] | RegExpConstant,RegExpNormalChar | -| file://:0:0:0:0 | ] | RegExpConstant,RegExpNormalChar | -| file://:0:0:0:0 | ]a-f] | RegExpConstant,RegExpNormalChar | | file://:0:0:0:0 | _ | RegExpConstant,RegExpNormalChar | | file://:0:0:0:0 | a | RegExpConstant,RegExpNormalChar | | file://:0:0:0:0 | a | RegExpConstant,RegExpNormalChar | @@ -129,7 +122,6 @@ term | file://:0:0:0:0 | a | RegExpConstant,RegExpNormalChar | | file://:0:0:0:0 | a | RegExpConstant,RegExpNormalChar | | file://:0:0:0:0 | a | RegExpConstant,RegExpNormalChar | -| file://:0:0:0:0 | a | RegExpConstant,RegExpNormalChar | | file://:0:0:0:0 | a* | RegExpStar | | file://:0:0:0:0 | a*b+c?d | RegExpSequence | | file://:0:0:0:0 | a+ | RegExpPlus | @@ -137,6 +129,7 @@ term | file://:0:0:0:0 | a-f | RegExpCharacterRange | | file://:0:0:0:0 | a-f | RegExpCharacterRange | | file://:0:0:0:0 | a-f] | RegExpConstant,RegExpNormalChar | +| file://:0:0:0:0 | a-f] | RegExpConstant,RegExpNormalChar | | file://:0:0:0:0 | a\\nb | RegExpSequence | | file://:0:0:0:0 | a\|b\|cd | RegExpAlt | | file://:0:0:0:0 | abc | RegExpConstant,RegExpNormalChar | @@ -162,7 +155,6 @@ term | file://:0:0:0:0 | b | RegExpConstant,RegExpNormalChar | | file://:0:0:0:0 | b | RegExpConstant,RegExpNormalChar | | file://:0:0:0:0 | b | RegExpConstant,RegExpNormalChar | -| file://:0:0:0:0 | b | RegExpConstant,RegExpNormalChar | | file://:0:0:0:0 | b+ | RegExpPlus | | file://:0:0:0:0 | b+ | RegExpPlus | | file://:0:0:0:0 | bar | RegExpConstant,RegExpNormalChar | @@ -192,10 +184,6 @@ regExpNormalCharValue | file://:0:0:0:0 | !a | !a | | file://:0:0:0:0 | - | - | | file://:0:0:0:0 | : | : | -| file://:0:0:0:0 | = | = | -| file://:0:0:0:0 | = | = | -| file://:0:0:0:0 | = | = | -| file://:0:0:0:0 | = | = | | file://:0:0:0:0 | A | A | | file://:0:0:0:0 | A | A | | file://:0:0:0:0 | A | A | @@ -210,8 +198,6 @@ regExpNormalCharValue | file://:0:0:0:0 | [ | [ | | file://:0:0:0:0 | [ | [ | | file://:0:0:0:0 | [ | [ | -| file://:0:0:0:0 | [ | [ | -| file://:0:0:0:0 | [ | [ | | file://:0:0:0:0 | \\0 | 0 | | file://:0:0:0:0 | \\0 | 0 | | file://:0:0:0:0 | \\D | D | @@ -234,8 +220,6 @@ regExpNormalCharValue | file://:0:0:0:0 | \| | \| | | file://:0:0:0:0 | ] | ] | | file://:0:0:0:0 | ] | ] | -| file://:0:0:0:0 | ] | ] | -| file://:0:0:0:0 | ]a-f] | ]a-f] | | file://:0:0:0:0 | _ | _ | | file://:0:0:0:0 | a | a | | file://:0:0:0:0 | a | a | @@ -249,7 +233,7 @@ regExpNormalCharValue | file://:0:0:0:0 | a | a | | file://:0:0:0:0 | a | a | | file://:0:0:0:0 | a | a | -| file://:0:0:0:0 | a | a | +| file://:0:0:0:0 | a-f] | a-f] | | file://:0:0:0:0 | a-f] | a-f] | | file://:0:0:0:0 | abc | abc | | file://:0:0:0:0 | abc | abc | @@ -270,7 +254,6 @@ regExpNormalCharValue | file://:0:0:0:0 | b | b | | file://:0:0:0:0 | b | b | | file://:0:0:0:0 | b | b | -| file://:0:0:0:0 | b | b | | file://:0:0:0:0 | bar | bar | | file://:0:0:0:0 | bar | bar | | file://:0:0:0:0 | c | c | From e631b08818ba9202b9d31364dc859e3c0f0d3e64 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 23 Jul 2026 10:24:37 +0000 Subject: [PATCH 23/26] C++: Replace non-standard \u{...} test with \uhhhh --- cpp/ql/test/library-tests/regex/parse.expected | 2 +- cpp/ql/test/library-tests/regex/regexp.cpp | 2 +- cpp/ql/test/library-tests/regex/regexp.expected | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/cpp/ql/test/library-tests/regex/parse.expected b/cpp/ql/test/library-tests/regex/parse.expected index 82c57962c2f2..fe733db3b56a 100644 --- a/cpp/ql/test/library-tests/regex/parse.expected +++ b/cpp/ql/test/library-tests/regex/parse.expected @@ -34,7 +34,7 @@ #-----| [RegExpConstant, RegExpEscape] \cA -#-----| [RegExpConstant, RegExpEscape] \u{987 +#-----| [RegExpConstant, RegExpEscape] \u0061 #-----| [RegExpConstant, RegExpNormalChar] A diff --git a/cpp/ql/test/library-tests/regex/regexp.cpp b/cpp/ql/test/library-tests/regex/regexp.cpp index 8806b6548077..64fe20952322 100644 --- a/cpp/ql/test/library-tests/regex/regexp.cpp +++ b/cpp/ql/test/library-tests/regex/regexp.cpp @@ -82,7 +82,7 @@ std::regex r_posix_equiv2("[A-F[[=b=]]a-f]"); std::regex r_posix4("[:digit:]"); // unicode -std::regex r_uni("\\u{9879}"); +std::regex r_uni("\\u0061"); // control escapes std::regex r_ctrl1("\\cA"); diff --git a/cpp/ql/test/library-tests/regex/regexp.expected b/cpp/ql/test/library-tests/regex/regexp.expected index ac7aa2b58d6b..56ba3c9ea1a8 100644 --- a/cpp/ql/test/library-tests/regex/regexp.expected +++ b/cpp/ql/test/library-tests/regex/regexp.expected @@ -100,7 +100,7 @@ term | file://:0:0:0:0 | \\s | RegExpCharacterClassEscape | | file://:0:0:0:0 | \\s\\S | RegExpSequence | | file://:0:0:0:0 | \\t | RegExpConstant,RegExpEscape | -| file://:0:0:0:0 | \\u{987 | RegExpConstant,RegExpEscape | +| file://:0:0:0:0 | \\u0061 | RegExpConstant,RegExpEscape | | file://:0:0:0:0 | \\w | RegExpCharacterClassEscape | | file://:0:0:0:0 | \\w | RegExpCharacterClassEscape | | file://:0:0:0:0 | \\w | RegExpCharacterClassEscape | @@ -213,7 +213,7 @@ regExpNormalCharValue | file://:0:0:0:0 | \\r | \r | | file://:0:0:0:0 | \\s | s | | file://:0:0:0:0 | \\t | \t | -| file://:0:0:0:0 | \\u{987 | \u0987 | +| file://:0:0:0:0 | \\u0061 | a | | file://:0:0:0:0 | \\w | w | | file://:0:0:0:0 | \\w | w | | file://:0:0:0:0 | \\w | w | From 85d46d5bf87c62df830673d42c3937a09a6bd8f0 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 23 Jul 2026 10:25:11 +0000 Subject: [PATCH 24/26] C++: Add coverage for lazy quantifiers and \f/\v escapes --- .../test/library-tests/regex/parse.expected | 28 +++++++++++++++++++ cpp/ql/test/library-tests/regex/regexp.cpp | 7 +++++ .../test/library-tests/regex/regexp.expected | 17 +++++++++++ 3 files changed, 52 insertions(+) diff --git a/cpp/ql/test/library-tests/regex/parse.expected b/cpp/ql/test/library-tests/regex/parse.expected index fe733db3b56a..148b8af0ac58 100644 --- a/cpp/ql/test/library-tests/regex/parse.expected +++ b/cpp/ql/test/library-tests/regex/parse.expected @@ -26,6 +26,18 @@ #-----| [RegExpConstant, RegExpNormalChar] b +#-----| [RegExpConstant, RegExpEscape] \f + +#-----| [RegExpConstant, RegExpEscape] \v + +#-----| [RegExpConstant, RegExpNormalChar] d + +#-----| [RegExpConstant, RegExpNormalChar] c + +#-----| [RegExpConstant, RegExpNormalChar] b + +#-----| [RegExpConstant, RegExpNormalChar] a + #-----| [RegExpConstant, RegExpEscape] \0 #-----| [RegExpConstant, RegExpEscape] \0 @@ -187,6 +199,10 @@ #-----| 1 -> [RegExpConstant, RegExpEscape] \n #-----| 2 -> [RegExpConstant, RegExpNormalChar] b +#-----| [RegExpSequence] \f\v +#-----| 0 -> [RegExpConstant, RegExpEscape] \f +#-----| 1 -> [RegExpConstant, RegExpEscape] \v + #-----| [RegExpSequence] [A-F[[=b=]]a-f] #-----| 0 -> [RegExpCharacterClass] [A-F[[=b=]] #-----| 1 -> [RegExpConstant, RegExpNormalChar] a-f] @@ -409,6 +425,18 @@ #-----| 0 -> [RegExpConstant, RegExpNormalChar] foo #-----| 1 -> [RegExpConstant, RegExpNormalChar] bar +#-----| [RegExpQuantifier] d{2,3}? +#-----| 0 -> [RegExpConstant, RegExpNormalChar] d + +#-----| [RegExpOpt] c?? +#-----| 0 -> [RegExpConstant, RegExpNormalChar] c + +#-----| [RegExpPlus] b+? +#-----| 0 -> [RegExpConstant, RegExpNormalChar] b + +#-----| [RegExpStar] a*? +#-----| 0 -> [RegExpConstant, RegExpNormalChar] a + #-----| [RegExpPlus] a+ #-----| 0 -> [RegExpConstant, RegExpNormalChar] a diff --git a/cpp/ql/test/library-tests/regex/regexp.cpp b/cpp/ql/test/library-tests/regex/regexp.cpp index 64fe20952322..15e35eb0ca2e 100644 --- a/cpp/ql/test/library-tests/regex/regexp.cpp +++ b/cpp/ql/test/library-tests/regex/regexp.cpp @@ -92,6 +92,13 @@ std::regex r_ctrl2("[\\cZ]"); std::regex r_nul1("\\0"); std::regex r_nul2("[\\0]"); +// Lazy quantifiers and additional supported escapes +std::regex r_lazy1("a*?"); +std::regex r_lazy2("b+?"); +std::regex r_lazy3("c??"); +std::regex r_lazy4("d{2,3}?"); +std::regex r_fv("\\f\\v"); + // String literal spellings for location tests std::regex r_loc_plain("a\\nb"); std::basic_regex r_loc_L(L"abc"); diff --git a/cpp/ql/test/library-tests/regex/regexp.expected b/cpp/ql/test/library-tests/regex/regexp.expected index 56ba3c9ea1a8..8bde18a3aa8b 100644 --- a/cpp/ql/test/library-tests/regex/regexp.expected +++ b/cpp/ql/test/library-tests/regex/regexp.expected @@ -93,6 +93,8 @@ term | file://:0:0:0:0 | \\cZ | RegExpConstant,RegExpEscape | | file://:0:0:0:0 | \\d | RegExpCharacterClassEscape | | file://:0:0:0:0 | \\d\\D | RegExpSequence | +| file://:0:0:0:0 | \\f | RegExpConstant,RegExpEscape | +| file://:0:0:0:0 | \\f\\v | RegExpSequence | | file://:0:0:0:0 | \\n | RegExpConstant,RegExpEscape | | file://:0:0:0:0 | \\n | RegExpConstant,RegExpEscape | | file://:0:0:0:0 | \\n\\r\\t | RegExpSequence | @@ -101,6 +103,7 @@ term | file://:0:0:0:0 | \\s\\S | RegExpSequence | | file://:0:0:0:0 | \\t | RegExpConstant,RegExpEscape | | file://:0:0:0:0 | \\u0061 | RegExpConstant,RegExpEscape | +| file://:0:0:0:0 | \\v | RegExpConstant,RegExpEscape | | file://:0:0:0:0 | \\w | RegExpCharacterClassEscape | | file://:0:0:0:0 | \\w | RegExpCharacterClassEscape | | file://:0:0:0:0 | \\w | RegExpCharacterClassEscape | @@ -122,7 +125,9 @@ term | file://:0:0:0:0 | a | RegExpConstant,RegExpNormalChar | | file://:0:0:0:0 | a | RegExpConstant,RegExpNormalChar | | file://:0:0:0:0 | a | RegExpConstant,RegExpNormalChar | +| file://:0:0:0:0 | a | RegExpConstant,RegExpNormalChar | | file://:0:0:0:0 | a* | RegExpStar | +| file://:0:0:0:0 | a*? | RegExpStar | | file://:0:0:0:0 | a*b+c?d | RegExpSequence | | file://:0:0:0:0 | a+ | RegExpPlus | | file://:0:0:0:0 | a-f | RegExpCharacterRange | @@ -155,15 +160,21 @@ term | file://:0:0:0:0 | b | RegExpConstant,RegExpNormalChar | | file://:0:0:0:0 | b | RegExpConstant,RegExpNormalChar | | file://:0:0:0:0 | b | RegExpConstant,RegExpNormalChar | +| file://:0:0:0:0 | b | RegExpConstant,RegExpNormalChar | | file://:0:0:0:0 | b+ | RegExpPlus | | file://:0:0:0:0 | b+ | RegExpPlus | +| file://:0:0:0:0 | b+? | RegExpPlus | | file://:0:0:0:0 | bar | RegExpConstant,RegExpNormalChar | | file://:0:0:0:0 | bar | RegExpConstant,RegExpNormalChar | | file://:0:0:0:0 | c | RegExpConstant,RegExpNormalChar | | file://:0:0:0:0 | c | RegExpConstant,RegExpNormalChar | +| file://:0:0:0:0 | c | RegExpConstant,RegExpNormalChar | | file://:0:0:0:0 | c? | RegExpOpt | +| file://:0:0:0:0 | c?? | RegExpOpt | | file://:0:0:0:0 | cd | RegExpConstant,RegExpNormalChar | | file://:0:0:0:0 | d | RegExpConstant,RegExpNormalChar | +| file://:0:0:0:0 | d | RegExpConstant,RegExpNormalChar | +| file://:0:0:0:0 | d{2,3}? | RegExpQuantifier | | file://:0:0:0:0 | e | RegExpConstant,RegExpNormalChar | | file://:0:0:0:0 | f | RegExpConstant,RegExpNormalChar | | file://:0:0:0:0 | f | RegExpConstant,RegExpNormalChar | @@ -208,12 +219,14 @@ regExpNormalCharValue | file://:0:0:0:0 | \\cA | cA | | file://:0:0:0:0 | \\cZ | cZ | | file://:0:0:0:0 | \\d | d | +| file://:0:0:0:0 | \\f | \u000c | | file://:0:0:0:0 | \\n | \n | | file://:0:0:0:0 | \\n | \n | | file://:0:0:0:0 | \\r | \r | | file://:0:0:0:0 | \\s | s | | file://:0:0:0:0 | \\t | \t | | file://:0:0:0:0 | \\u0061 | a | +| file://:0:0:0:0 | \\v | \u000b | | file://:0:0:0:0 | \\w | w | | file://:0:0:0:0 | \\w | w | | file://:0:0:0:0 | \\w | w | @@ -233,6 +246,7 @@ regExpNormalCharValue | file://:0:0:0:0 | a | a | | file://:0:0:0:0 | a | a | | file://:0:0:0:0 | a | a | +| file://:0:0:0:0 | a | a | | file://:0:0:0:0 | a-f] | a-f] | | file://:0:0:0:0 | a-f] | a-f] | | file://:0:0:0:0 | abc | abc | @@ -254,12 +268,15 @@ regExpNormalCharValue | file://:0:0:0:0 | b | b | | file://:0:0:0:0 | b | b | | file://:0:0:0:0 | b | b | +| file://:0:0:0:0 | b | b | | file://:0:0:0:0 | bar | bar | | file://:0:0:0:0 | bar | bar | | file://:0:0:0:0 | c | c | | file://:0:0:0:0 | c | c | +| file://:0:0:0:0 | c | c | | file://:0:0:0:0 | cd | cd | | file://:0:0:0:0 | d | d | +| file://:0:0:0:0 | d | d | | file://:0:0:0:0 | e | e | | file://:0:0:0:0 | f | f | | file://:0:0:0:0 | f | f | From 53ea48874167f0a6d787123934fb3d8be6f945b3 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 23 Jul 2026 10:25:48 +0000 Subject: [PATCH 25/26] C++: Verify [\b] is backspace inside character classes --- cpp/ql/test/library-tests/regex/parse.expected | 5 +++++ cpp/ql/test/library-tests/regex/regexp.cpp | 1 + cpp/ql/test/library-tests/regex/regexp.expected | 3 +++ 3 files changed, 9 insertions(+) diff --git a/cpp/ql/test/library-tests/regex/parse.expected b/cpp/ql/test/library-tests/regex/parse.expected index 148b8af0ac58..80833567ffce 100644 --- a/cpp/ql/test/library-tests/regex/parse.expected +++ b/cpp/ql/test/library-tests/regex/parse.expected @@ -128,6 +128,8 @@ #-----| [RegExpConstant, RegExpNormalChar] A-F] +#-----| [RegExpConstant, RegExpEscape] \b + #-----| [RegExpConstant, RegExpNormalChar] | #-----| [RegExpConstant, RegExpNormalChar] - @@ -378,6 +380,9 @@ #-----| 0 -> [RegExpConstant, RegExpNormalChar] [ #-----| 1 -> [RegExpCharacterRange] a-f +#-----| [RegExpCharacterClass] [\b] +#-----| 0 -> [RegExpConstant, RegExpEscape] \b + #-----| [RegExpCharacterClass] [|] #-----| 0 -> [RegExpConstant, RegExpNormalChar] | diff --git a/cpp/ql/test/library-tests/regex/regexp.cpp b/cpp/ql/test/library-tests/regex/regexp.cpp index 15e35eb0ca2e..a1e1acb11c5a 100644 --- a/cpp/ql/test/library-tests/regex/regexp.cpp +++ b/cpp/ql/test/library-tests/regex/regexp.cpp @@ -37,6 +37,7 @@ std::regex r_cc7("[]]"); // MRI gives a warning, but accepts this as matching std::regex r_cc8("[^]]"); // MRI gives a warning, but accepts this as matching anything except ']' std::regex r_cc9("[^-]"); std::regex r_cc10("[|]"); +std::regex r_cc11("[\\b]"); // Nested character classes (BAD - not parsed correctly) std::regex r_nested("[[a-f]A-F]"); diff --git a/cpp/ql/test/library-tests/regex/regexp.expected b/cpp/ql/test/library-tests/regex/regexp.expected index 8bde18a3aa8b..a56d54663162 100644 --- a/cpp/ql/test/library-tests/regex/regexp.expected +++ b/cpp/ql/test/library-tests/regex/regexp.expected @@ -67,6 +67,7 @@ term | file://:0:0:0:0 | [[a-f] | RegExpCharacterClass | | file://:0:0:0:0 | [[a-f]A-F] | RegExpSequence | | file://:0:0:0:0 | [\\0] | RegExpCharacterClass | +| file://:0:0:0:0 | [\\b] | RegExpCharacterClass | | file://:0:0:0:0 | [\\cZ] | RegExpCharacterClass | | file://:0:0:0:0 | [\\w] | RegExpCharacterClass | | file://:0:0:0:0 | [\\w]+ | RegExpPlus | @@ -87,6 +88,7 @@ term | file://:0:0:0:0 | \\[ | RegExpConstant,RegExpEscape | | file://:0:0:0:0 | \\[\\][123] | RegExpSequence | | file://:0:0:0:0 | \\] | RegExpConstant,RegExpEscape | +| file://:0:0:0:0 | \\b | RegExpConstant,RegExpEscape | | file://:0:0:0:0 | \\b | RegExpSpecialChar | | file://:0:0:0:0 | \\b!a\\B | RegExpSequence | | file://:0:0:0:0 | \\cA | RegExpConstant,RegExpEscape | @@ -216,6 +218,7 @@ regExpNormalCharValue | file://:0:0:0:0 | \\W | W | | file://:0:0:0:0 | \\[ | [ | | file://:0:0:0:0 | \\] | ] | +| file://:0:0:0:0 | \\b | b | | file://:0:0:0:0 | \\cA | cA | | file://:0:0:0:0 | \\cZ | cZ | | file://:0:0:0:0 | \\d | d | From 3f59f4809ed87e289adf598d516c25481ecdfeed Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 23 Jul 2026 10:27:00 +0000 Subject: [PATCH 26/26] C++: Add change note for std::regex ECMAScript parser alignment --- .../change-notes/2026-07-23-std-regex-ecmascript-parser.md | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 cpp/ql/lib/change-notes/2026-07-23-std-regex-ecmascript-parser.md diff --git a/cpp/ql/lib/change-notes/2026-07-23-std-regex-ecmascript-parser.md b/cpp/ql/lib/change-notes/2026-07-23-std-regex-ecmascript-parser.md new file mode 100644 index 000000000000..03d3d4cfedaa --- /dev/null +++ b/cpp/ql/lib/change-notes/2026-07-23-std-regex-ecmascript-parser.md @@ -0,0 +1,4 @@ +--- +category: minorAnalysis +--- +* The C++ regular-expression parser has been aligned to the ECMAScript grammar used by `std::regex`.