Swift: Implement 'isUsedAsReplace'.

This commit is contained in:
Geoffrey White
2023-10-23 19:34:00 +01:00
parent 435638a5bb
commit 8f115bfd06
5 changed files with 23 additions and 31 deletions

View File

@@ -330,6 +330,13 @@ abstract class RegexEval extends CallExpr {
*/
DataFlow::Node getAnOptionsInput() { none() }
/**
* Holds if this regular expression evaluation is a 'replacement' operation,
* such as replacing all matches of the regular expression in the input
* string with another string.
*/
abstract predicate isUsedAsReplace();
/**
* Gets a regular expression value that is evaluated here (if any can be identified).
*/
@@ -416,6 +423,10 @@ private class AlwaysRegexEval extends RegexEval {
override DataFlow::Node getRegexInputNode() { result = regexInput }
override DataFlow::Node getStringInputNode() { result = stringInput }
override predicate isUsedAsReplace() {
this.getStaticTarget().getName().matches(["replac%", "stringByReplac%", "trim%"])
}
}
/**
@@ -508,4 +519,6 @@ private class NSStringCompareOptionsRegexEval extends RegexEval instanceof NSStr
override DataFlow::Node getAnOptionsInput() {
result = this.(NSStringCompareOptionsPotentialRegexEval).getAnOptionsInput()
}
override predicate isUsedAsReplace() { this.getStaticTarget().getName().matches(["replac%"]) }
}