mirror of
https://github.com/github/codeql.git
synced 2026-04-27 01:35:13 +02:00
Merge pull request #5400 from erik-krogh/replaceCallbacks
Approved by asgerf
This commit is contained in:
@@ -149,6 +149,25 @@ class StringReplaceCall extends DataFlow::MethodCallNode {
|
||||
pr.flowsTo(replacer.getAReturn()) and
|
||||
map.hasPropertyWrite(old, any(DataFlow::Node repl | repl.getStringValue() = new))
|
||||
)
|
||||
or
|
||||
// str.replace(regex, match => {
|
||||
// if (match === 'old') return 'new';
|
||||
// if (match === 'foo') return 'bar';
|
||||
// ...
|
||||
// })
|
||||
exists(
|
||||
DataFlow::FunctionNode replacer, ConditionGuardNode guard, EqualityTest test,
|
||||
DataFlow::Node ret
|
||||
|
|
||||
replacer = getCallback(1) and
|
||||
guard.getOutcome() = test.getPolarity() and
|
||||
guard.getTest() = test and
|
||||
replacer.getParameter(0).flowsToExpr(test.getAnOperand()) and
|
||||
test.getAnOperand().getStringValue() = old and
|
||||
ret = replacer.getAReturn() and
|
||||
guard.dominates(ret.getBasicBlock()) and
|
||||
new = ret.getStringValue()
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -51,7 +51,9 @@ class StringReplaceCallSequence extends DataFlow::CallNode {
|
||||
|
||||
/** Gets a string that is the replacement of this call. */
|
||||
string getAReplacementString() {
|
||||
// this is more restrictive than `StringReplaceCall::replaces/2`, in the name of precision
|
||||
getAMember().replaces(_, result)
|
||||
or
|
||||
// StringReplaceCall::replaces/2 can't always find the `old` string, so this is added as a fallback.
|
||||
getAMember().getRawReplacement().getStringValue() = result
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user