Skip to content

Commit

Permalink
JS: brought back isGlobal predicate in RegExpCreationNode and added m…
Browse files Browse the repository at this point in the history
…aybeGlobal for more convenience.
  • Loading branch information
Napalys committed Nov 28, 2024
1 parent 5b7f498 commit 7d2b6c9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
8 changes: 2 additions & 6 deletions javascript/ql/lib/semmle/javascript/StandardLibrary.qll
Original file line number Diff line number Diff line change
Expand Up @@ -115,17 +115,13 @@ class StringReplaceCall extends DataFlow::MethodCallNode {
* Holds if this is a global replacement, that is, the first argument is a regular expression
* with the `g` flag, or this is a call to `.replaceAll()`.
*/
predicate isGlobal() {
RegExp::isGlobal(this.getRegExp().getFlags()) or this.getMethodName() = "replaceAll"
}
predicate isGlobal() { this.getRegExp().isGlobal() or this.getMethodName() = "replaceAll" }

/**
* Holds if this is a global replacement, that is, the first argument is a regular expression
* with the `g` flag or unknown flags, or this is a call to `.replaceAll()`.
*/
predicate maybeGlobal() {
RegExp::maybeGlobal(this.getRegExp().tryGetFlags()) or this.getMethodName() = "replaceAll"
}
predicate maybeGlobal() { this.getRegExp().maybeGlobal() or this.getMethodName() = "replaceAll" }

/**
* Holds if this call to `replace` replaces `old` with `new`.
Expand Down
6 changes: 6 additions & 0 deletions javascript/ql/lib/semmle/javascript/dataflow/Nodes.qll
Original file line number Diff line number Diff line change
Expand Up @@ -1682,6 +1682,12 @@ class RegExpCreationNode extends DataFlow::SourceNode {
result = this.(RegExpLiteralNode).getFlags()
}

/** Holds if the constructed predicate has the `g` flag. */
predicate isGlobal() { RegExp::isGlobal(this.getFlags()) }

/** Holds if the constructed predicate has the `g` flag or unknown flags. */
predicate maybeGlobal() { RegExp::isGlobal(this.tryGetFlags()) }

/** Gets a data flow node referring to this regular expression. */
private DataFlow::SourceNode getAReference(DataFlow::TypeTracker t) {
t.start() and
Expand Down

0 comments on commit 7d2b6c9

Please sign in to comment.