Skip to content

Commit 7d2b6c9

Browse files
committed
JS: brought back isGlobal predicate in RegExpCreationNode and added maybeGlobal for more convenience.
1 parent 5b7f498 commit 7d2b6c9

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

javascript/ql/lib/semmle/javascript/StandardLibrary.qll

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -115,17 +115,13 @@ class StringReplaceCall extends DataFlow::MethodCallNode {
115115
* Holds if this is a global replacement, that is, the first argument is a regular expression
116116
* with the `g` flag, or this is a call to `.replaceAll()`.
117117
*/
118-
predicate isGlobal() {
119-
RegExp::isGlobal(this.getRegExp().getFlags()) or this.getMethodName() = "replaceAll"
120-
}
118+
predicate isGlobal() { this.getRegExp().isGlobal() or this.getMethodName() = "replaceAll" }
121119

122120
/**
123121
* Holds if this is a global replacement, that is, the first argument is a regular expression
124122
* with the `g` flag or unknown flags, or this is a call to `.replaceAll()`.
125123
*/
126-
predicate maybeGlobal() {
127-
RegExp::maybeGlobal(this.getRegExp().tryGetFlags()) or this.getMethodName() = "replaceAll"
128-
}
124+
predicate maybeGlobal() { this.getRegExp().maybeGlobal() or this.getMethodName() = "replaceAll" }
129125

130126
/**
131127
* Holds if this call to `replace` replaces `old` with `new`.

javascript/ql/lib/semmle/javascript/dataflow/Nodes.qll

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1682,6 +1682,12 @@ class RegExpCreationNode extends DataFlow::SourceNode {
16821682
result = this.(RegExpLiteralNode).getFlags()
16831683
}
16841684

1685+
/** Holds if the constructed predicate has the `g` flag. */
1686+
predicate isGlobal() { RegExp::isGlobal(this.getFlags()) }
1687+
1688+
/** Holds if the constructed predicate has the `g` flag or unknown flags. */
1689+
predicate maybeGlobal() { RegExp::isGlobal(this.tryGetFlags()) }
1690+
16851691
/** Gets a data flow node referring to this regular expression. */
16861692
private DataFlow::SourceNode getAReference(DataFlow::TypeTracker t) {
16871693
t.start() and

0 commit comments

Comments
 (0)