@@ -15,36 +15,30 @@ private import codeql.ruby.Regexp as RE
15
15
* We heuristically include any call to a method matching the above names,
16
16
* provided it has exactly two arguments and a receiver.
17
17
*/
18
- class StringSubstitutionCall extends DataFlow:: Node {
19
- private ExprNodes:: MethodCallCfgNode exprNode ;
20
-
18
+ class StringSubstitutionCall extends DataFlow:: CallNode {
21
19
StringSubstitutionCall ( ) {
22
- this .asExpr ( ) = exprNode and
23
- exprNode .getExpr ( ) .getMethodName ( ) = [ "sub" , "sub!" , "gsub" , "gsub!" ] and
24
- exists ( exprNode .getReceiver ( ) ) and
25
- exprNode .getNumberOfArguments ( ) = 2
20
+ this .getMethodName ( ) = [ "sub" , "sub!" , "gsub" , "gsub!" ] and
21
+ exists ( this .getReceiver ( ) ) and
22
+ this .getNumberOfArguments ( ) = 2
26
23
}
27
24
28
25
/**
29
26
* Holds if this is a global substitution, i.e. this is a call to `gsub` or
30
27
* `gsub!`.
31
28
*/
32
- predicate isGlobal ( ) { exprNode . getExpr ( ) .getMethodName ( ) = [ "gsub" , "gsub!" ] }
29
+ predicate isGlobal ( ) { this .getMethodName ( ) = [ "gsub" , "gsub!" ] }
33
30
34
31
/**
35
32
* Holds if this is a destructive substitution, i.e. this is a call to `sub!`
36
33
* or `gsub!`.
37
34
*/
38
- predicate isDestructive ( ) { exprNode .getExpr ( ) .getMethodName ( ) = [ "sub!" , "gsub!" ] }
39
-
40
- /** Gets the receiver of this call. */
41
- DataFlow:: Node getReceiver ( ) { result .asExpr ( ) = exprNode .getReceiver ( ) }
35
+ predicate isDestructive ( ) { this .getMethodName ( ) = [ "sub!" , "gsub!" ] }
42
36
43
37
/** Gets the first argument to this call. */
44
- DataFlow:: Node getPatternArgument ( ) { result . asExpr ( ) = exprNode .getArgument ( 0 ) }
38
+ DataFlow:: Node getPatternArgument ( ) { result = this .getArgument ( 0 ) }
45
39
46
40
/** Gets the second argument to this call. */
47
- DataFlow:: Node getReplacementArgument ( ) { result . asExpr ( ) = exprNode .getArgument ( 1 ) }
41
+ DataFlow:: Node getReplacementArgument ( ) { result = this .getArgument ( 1 ) }
48
42
49
43
/**
50
44
* Gets the regular expression passed as the first (pattern) argument in this
@@ -60,13 +54,15 @@ class StringSubstitutionCall extends DataFlow::Node {
60
54
* Gets the string value passed as the first (pattern) argument in this call,
61
55
* if any.
62
56
*/
63
- string getPatternString ( ) { result = exprNode .getArgument ( 0 ) .getConstantValue ( ) .getString ( ) }
57
+ string getPatternString ( ) { result = this .getArgument ( 0 ) . asExpr ( ) .getConstantValue ( ) .getString ( ) }
64
58
65
59
/**
66
60
* Gets the string value passed as the second (replacement) argument in this
67
61
* call, if any.
68
62
*/
69
- string getReplacementString ( ) { result = exprNode .getArgument ( 1 ) .getConstantValue ( ) .getString ( ) }
63
+ string getReplacementString ( ) {
64
+ result = this .getArgument ( 1 ) .asExpr ( ) .getConstantValue ( ) .getString ( )
65
+ }
70
66
71
67
/** Gets a string that is being replaced by this call. */
72
68
string getAReplacedString ( ) {
0 commit comments