@@ -69,10 +69,15 @@ abstract class RegexCreation extends DataFlow::Node {
69
69
abstract DataFlow:: Node getStringInput ( ) ;
70
70
71
71
/**
72
- * Gets a dataflow node for the options input that might contain parse mode
72
+ * Gets a dataflow node for an options input that might contain parse mode
73
73
* flags (if any).
74
74
*/
75
- DataFlow:: Node getOptionsInput ( ) { none ( ) }
75
+ DataFlow:: Node getAnOptionsInput ( ) { none ( ) }
76
+
77
+ /**
78
+ * DEPRECATED: Use `getAnOptionsInput()` instead.
79
+ */
80
+ deprecated DataFlow:: Node getOptionsInput ( ) { result = this .getAnOptionsInput ( ) }
76
81
}
77
82
78
83
/**
@@ -110,7 +115,7 @@ private class NSRegularExpressionRegexCreation extends RegexCreation {
110
115
111
116
override DataFlow:: Node getStringInput ( ) { result = input }
112
117
113
- override DataFlow:: Node getOptionsInput ( ) {
118
+ override DataFlow:: Node getAnOptionsInput ( ) {
114
119
result .asExpr ( ) = this .asExpr ( ) .( CallExpr ) .getArgument ( 1 ) .getExpr ( )
115
120
}
116
121
}
@@ -265,27 +270,27 @@ class NSRegularExpressionRegexAdditionalFlowStep extends RegexAdditionalFlowStep
265
270
*/
266
271
abstract class RegexEval extends CallExpr {
267
272
/**
268
- * Gets the input to this call that is the regular expression being evaluated. This may
269
- * be a regular expression object or a string literal.
273
+ * Gets the input to this call that is the regular expression being evaluated.
274
+ * This may be a regular expression object or a string literal.
270
275
*/
271
- abstract Expr getRegexInput ( ) ;
276
+ abstract DataFlow :: Node getRegexInput ( ) ;
272
277
273
278
/**
274
279
* Gets the input to this call that is the string the regular expression is evaluated on.
275
280
*/
276
- abstract Expr getStringInput ( ) ;
281
+ abstract DataFlow :: Node getStringInput ( ) ;
277
282
278
283
/**
279
284
* Gets a regular expression value that is evaluated here (if any can be identified).
280
285
*/
281
286
RegExp getARegex ( ) {
282
287
// string literal used directly as a regex
283
- DataFlow:: exprNode ( result ) .( ParsedStringRegex ) .getAParse ( ) . asExpr ( ) = this .getRegexInput ( )
288
+ DataFlow:: exprNode ( result ) .( ParsedStringRegex ) .getAParse ( ) = this .getRegexInput ( )
284
289
or
285
290
// string literal -> regex object -> use
286
291
exists ( RegexCreation regexCreation |
287
292
DataFlow:: exprNode ( result ) .( ParsedStringRegex ) .getAParse ( ) = regexCreation .getStringInput ( ) and
288
- RegexUseFlow:: flow ( regexCreation , DataFlow :: exprNode ( this .getRegexInput ( ) ) )
293
+ RegexUseFlow:: flow ( regexCreation , this .getRegexInput ( ) )
289
294
)
290
295
}
291
296
@@ -298,7 +303,7 @@ abstract class RegexEval extends CallExpr {
298
303
// parse mode flag is set
299
304
any ( RegexAdditionalFlowStep s ) .setsParseMode ( setNode , result , true ) and
300
305
// reaches this eval
301
- RegexParseModeFlow:: flow ( setNode , DataFlow :: exprNode ( this .getRegexInput ( ) ) )
306
+ RegexParseModeFlow:: flow ( setNode , this .getRegexInput ( ) )
302
307
)
303
308
}
304
309
}
@@ -307,15 +312,15 @@ abstract class RegexEval extends CallExpr {
307
312
* A call to a function that always evaluates a regular expression.
308
313
*/
309
314
private class AlwaysRegexEval extends RegexEval {
310
- Expr regexInput ;
311
- Expr stringInput ;
315
+ DataFlow :: Node regexInput ;
316
+ DataFlow :: Node stringInput ;
312
317
313
318
AlwaysRegexEval ( ) {
314
319
this .getStaticTarget ( )
315
320
.( Method )
316
321
.hasQualifiedName ( "Regex" , [ "firstMatch(in:)" , "prefixMatch(in:)" , "wholeMatch(in:)" ] ) and
317
- regexInput = this .getQualifier ( ) and
318
- stringInput = this .getArgument ( 0 ) .getExpr ( )
322
+ regexInput . asExpr ( ) = this .getQualifier ( ) and
323
+ stringInput . asExpr ( ) = this .getArgument ( 0 ) .getExpr ( )
319
324
or
320
325
this .getStaticTarget ( )
321
326
.( Method )
@@ -327,8 +332,8 @@ private class AlwaysRegexEval extends RegexEval {
327
332
"replaceMatches(in:options:range:withTemplate:)" ,
328
333
"stringByReplacingMatches(in:options:range:withTemplate:)"
329
334
] ) and
330
- regexInput = this .getQualifier ( ) and
331
- stringInput = this .getArgument ( 0 ) .getExpr ( )
335
+ regexInput . asExpr ( ) = this .getQualifier ( ) and
336
+ stringInput . asExpr ( ) = this .getArgument ( 0 ) .getExpr ( )
332
337
or
333
338
this .getStaticTarget ( )
334
339
.( Method )
@@ -339,8 +344,8 @@ private class AlwaysRegexEval extends RegexEval {
339
344
"split(separator:maxSplits:omittingEmptySubsequences:)" , "starts(with:)" ,
340
345
"trimmingPrefix(_:)" , "wholeMatch(of:)"
341
346
] ) and
342
- regexInput = this .getArgument ( 0 ) .getExpr ( ) and
343
- stringInput = this .getQualifier ( )
347
+ regexInput . asExpr ( ) = this .getArgument ( 0 ) .getExpr ( ) and
348
+ stringInput . asExpr ( ) = this .getQualifier ( )
344
349
or
345
350
this .getStaticTarget ( )
346
351
.( Method )
@@ -351,23 +356,23 @@ private class AlwaysRegexEval extends RegexEval {
351
356
"replacing(_:with:maxReplacements:)" , "replacing(_:with:subrange:maxReplacements:)" ,
352
357
"trimPrefix(_:)"
353
358
] ) and
354
- regexInput = this .getArgument ( 0 ) .getExpr ( ) and
355
- stringInput = this .getQualifier ( )
359
+ regexInput . asExpr ( ) = this .getArgument ( 0 ) .getExpr ( ) and
360
+ stringInput . asExpr ( ) = this .getQualifier ( )
356
361
}
357
362
358
- override Expr getRegexInput ( ) { result = regexInput }
363
+ override DataFlow :: Node getRegexInput ( ) { result = regexInput }
359
364
360
- override Expr getStringInput ( ) { result = stringInput }
365
+ override DataFlow :: Node getStringInput ( ) { result = stringInput }
361
366
}
362
367
363
368
/**
364
369
* A call to a function that sometimes evaluates a regular expression, if
365
370
* `options: .regularExpression` is set as an argument.
366
371
*/
367
372
private class SometimesRegexEval extends RegexEval {
368
- Expr regexInput ;
369
- Expr stringInput ;
370
- Expr optionsInput ;
373
+ DataFlow :: Node regexInput ;
374
+ DataFlow :: Node stringInput ;
375
+ DataFlow :: Node optionsInput ;
371
376
372
377
SometimesRegexEval ( ) {
373
378
(
@@ -384,13 +389,13 @@ private class SometimesRegexEval extends RegexEval {
384
389
"replacingOccurrences(of:with:options:range:)"
385
390
] )
386
391
) and
387
- regexInput = this .getArgument ( 0 ) .getExpr ( ) and
388
- stringInput = this .getQualifier ( ) and
389
- optionsInput = this .getArgumentWithLabel ( "options" ) .getExpr ( )
392
+ regexInput . asExpr ( ) = this .getArgument ( 0 ) .getExpr ( ) and
393
+ stringInput . asExpr ( ) = this .getQualifier ( ) and
394
+ optionsInput . asExpr ( ) = this .getArgumentWithLabel ( "options" ) .getExpr ( )
390
395
// TODO: check options may have value `.regularExpression`
391
396
}
392
397
393
- override Expr getRegexInput ( ) { result = regexInput }
398
+ override DataFlow :: Node getRegexInput ( ) { result = regexInput }
394
399
395
- override Expr getStringInput ( ) { result = stringInput }
400
+ override DataFlow :: Node getStringInput ( ) { result = stringInput }
396
401
}
0 commit comments