@@ -15,36 +15,30 @@ private import codeql.ruby.Regexp as RE
1515 * We heuristically include any call to a method matching the above names,
1616 * provided it has exactly two arguments and a receiver.
1717 */
18- class StringSubstitutionCall extends DataFlow:: Node {
19- private ExprNodes:: MethodCallCfgNode exprNode ;
20-
18+ class StringSubstitutionCall extends DataFlow:: CallNode {
2119 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
2623 }
2724
2825 /**
2926 * Holds if this is a global substitution, i.e. this is a call to `gsub` or
3027 * `gsub!`.
3128 */
32- predicate isGlobal ( ) { exprNode . getExpr ( ) .getMethodName ( ) = [ "gsub" , "gsub!" ] }
29+ predicate isGlobal ( ) { this .getMethodName ( ) = [ "gsub" , "gsub!" ] }
3330
3431 /**
3532 * Holds if this is a destructive substitution, i.e. this is a call to `sub!`
3633 * or `gsub!`.
3734 */
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!" ] }
4236
4337 /** Gets the first argument to this call. */
44- DataFlow:: Node getPatternArgument ( ) { result . asExpr ( ) = exprNode .getArgument ( 0 ) }
38+ DataFlow:: Node getPatternArgument ( ) { result = this .getArgument ( 0 ) }
4539
4640 /** Gets the second argument to this call. */
47- DataFlow:: Node getReplacementArgument ( ) { result . asExpr ( ) = exprNode .getArgument ( 1 ) }
41+ DataFlow:: Node getReplacementArgument ( ) { result = this .getArgument ( 1 ) }
4842
4943 /**
5044 * Gets the regular expression passed as the first (pattern) argument in this
@@ -60,13 +54,15 @@ class StringSubstitutionCall extends DataFlow::Node {
6054 * Gets the string value passed as the first (pattern) argument in this call,
6155 * if any.
6256 */
63- string getPatternString ( ) { result = exprNode .getArgument ( 0 ) .getConstantValue ( ) .getString ( ) }
57+ string getPatternString ( ) { result = this .getArgument ( 0 ) . asExpr ( ) .getConstantValue ( ) .getString ( ) }
6458
6559 /**
6660 * Gets the string value passed as the second (replacement) argument in this
6761 * call, if any.
6862 */
69- string getReplacementString ( ) { result = exprNode .getArgument ( 1 ) .getConstantValue ( ) .getString ( ) }
63+ string getReplacementString ( ) {
64+ result = this .getArgument ( 1 ) .asExpr ( ) .getConstantValue ( ) .getString ( )
65+ }
7066
7167 /** Gets a string that is being replaced by this call. */
7268 string getAReplacedString ( ) {
0 commit comments