Skip to content

Commit

Permalink
JS: MissingUnicodeFlag now uses flags from RegExpLiteral, upgraded to…
Browse files Browse the repository at this point in the history
… accept v flag as well.
  • Loading branch information
Napalys committed Nov 22, 2024
1 parent 2bcb7cf commit f1dccaf
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 1 deletion.
3 changes: 3 additions & 0 deletions javascript/ql/lib/semmle/javascript/Expr.qll
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,9 @@ class RegExpLiteral extends @regexp_literal, Literal, RegExpParent {
/** Holds if this regular expression has an `s` flag. */
predicate isDotAll() { RegExp::isDotAll(this.getFlags()) }

// /** Holds if this regular expression has an `u` flag. */
predicate isUnicode() { RegExp::isUnicode(this.getFlags()) }

Check warning on line 485 in javascript/ql/lib/semmle/javascript/Expr.qll

View workflow job for this annotation

GitHub Actions / qldoc

Missing QLdoc for member-predicate Expr::RegExpLiteral::isUnicode/0

/** Holds if this regular expression has an `v` flag. */
predicate isUnicodeSets() { RegExp::isUnicodeSets(this.getFlags()) }

Expand Down
8 changes: 8 additions & 0 deletions javascript/ql/lib/semmle/javascript/Regexp.qll
Original file line number Diff line number Diff line change
Expand Up @@ -1162,6 +1162,10 @@ module RegExp {
bindingset[flags]
predicate isDotAll(string flags) { flags.matches("%s%") }

/** Holds if `flags` includes the `u` flag. */
bindingset[flags]
predicate isUnicode(string flags) { flags.matches("%u%") }

/** Holds if `flags` includes the `v` flag. */
bindingset[flags]
predicate isUnicodeSets(string flags) { flags.matches("%v%") }
Expand All @@ -1182,6 +1186,10 @@ module RegExp {
bindingset[flags]
predicate maybeDotAll(string flags) { flags = unknownFlag() or isDotAll(flags) }

/** Holds if `flags` includes the `s` flag or is the unknown flag `?`. */
bindingset[flags]
predicate maybeUnicodeSets(string flags) { flags = unknownFlag() or isUnicodeSets(flags) }

/** Holds if `term` and all of its disjuncts are anchored on both ends. */
predicate isFullyAnchoredTerm(RegExpTerm term) {
exists(RegExpSequence seq | term = seq |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import javascript
from RegExpLiteral literal, RegExpConstant wideConstant
where
wideConstant.getLiteral() = literal and
not literal.getFlags().matches("%u%") and
not (literal.isUnicode() or literal.isUnicodeSets()) and
wideConstant.getValue().length() > 1 and
(
wideConstant.getParent() instanceof RegExpCharacterClass
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
/[𒍀-𒍅]/u; // OK
/𒍀+/; // NOT OK
/𒍀+/u; // OK
/𒍀+/v; // OK
/(𒍀)+/; // OK

0 comments on commit f1dccaf

Please sign in to comment.