Skip to content

Commit 9bd3dc7

Browse files
committed
JS: MissingUnicodeFlag now uses flags from RegExpLiteral, upgraded to accept v flag as well.
1 parent 2bcb7cf commit 9bd3dc7

File tree

4 files changed

+13
-1
lines changed

4 files changed

+13
-1
lines changed

javascript/ql/lib/semmle/javascript/Expr.qll

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,9 @@ class RegExpLiteral extends @regexp_literal, Literal, RegExpParent {
481481
/** Holds if this regular expression has an `s` flag. */
482482
predicate isDotAll() { RegExp::isDotAll(this.getFlags()) }
483483

484+
/** Holds if this regular expression has an `u` flag. */
485+
predicate isUnicode() { RegExp::isUnicode(this.getFlags()) }
486+
484487
/** Holds if this regular expression has an `v` flag. */
485488
predicate isUnicodeSets() { RegExp::isUnicodeSets(this.getFlags()) }
486489

javascript/ql/lib/semmle/javascript/Regexp.qll

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1162,6 +1162,10 @@ module RegExp {
11621162
bindingset[flags]
11631163
predicate isDotAll(string flags) { flags.matches("%s%") }
11641164

1165+
/** Holds if `flags` includes the `u` flag. */
1166+
bindingset[flags]
1167+
predicate isUnicode(string flags) { flags.matches("%u%") }
1168+
11651169
/** Holds if `flags` includes the `v` flag. */
11661170
bindingset[flags]
11671171
predicate isUnicodeSets(string flags) { flags.matches("%v%") }
@@ -1182,6 +1186,10 @@ module RegExp {
11821186
bindingset[flags]
11831187
predicate maybeDotAll(string flags) { flags = unknownFlag() or isDotAll(flags) }
11841188

1189+
/** Holds if `flags` includes the `s` flag or is the unknown flag `?`. */
1190+
bindingset[flags]
1191+
predicate maybeUnicodeSets(string flags) { flags = unknownFlag() or isUnicodeSets(flags) }
1192+
11851193
/** Holds if `term` and all of its disjuncts are anchored on both ends. */
11861194
predicate isFullyAnchoredTerm(RegExpTerm term) {
11871195
exists(RegExpSequence seq | term = seq |

javascript/ql/test/library-tests/RegExp/MissingUnicodeFlag/MissingUnicodeFlag.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import javascript
33
from RegExpLiteral literal, RegExpConstant wideConstant
44
where
55
wideConstant.getLiteral() = literal and
6-
not literal.getFlags().matches("%u%") and
6+
not (literal.isUnicode() or literal.isUnicodeSets()) and
77
wideConstant.getValue().length() > 1 and
88
(
99
wideConstant.getParent() instanceof RegExpCharacterClass

javascript/ql/test/library-tests/RegExp/MissingUnicodeFlag/tst.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22
/[𒍀-𒍅]/u; // OK
33
/𒍀+/; // NOT OK
44
/𒍀+/u; // OK
5+
/𒍀+/v; // OK
56
/(𒍀)+/; // OK

0 commit comments

Comments
 (0)