Skip to content

Commit 6bb24f9

Browse files
committed
Ruby: matchesEmptyString -> isNullable
Rename RegExpLiteral.matchesEmptyString to isNullable, to match the JS version.
1 parent 3fba4a5 commit 6bb24f9

File tree

2 files changed

+25
-29
lines changed

2 files changed

+25
-29
lines changed

ruby/ql/lib/codeql/ruby/regexp/RegExpTreeView.qll

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ class RegExpTerm extends RegExpParent {
270270
override string getAPrimaryQlClass() { result = "RegExpTerm" }
271271

272272
/** Holds if this regular expression term can match the empty string. */
273-
predicate matchesEmptyString() { none() }
273+
predicate isNullable() { none() }
274274

275275
/** Gets a string matched by this regular expression. */
276276
string getAMatch() { none() }
@@ -333,7 +333,7 @@ class RegExpStar extends InfiniteRepetitionQuantifier {
333333

334334
override string getAPrimaryQlClass() { result = "RegExpStar" }
335335

336-
override predicate matchesEmptyString() { any() }
336+
override predicate isNullable() { any() }
337337
}
338338

339339
/**
@@ -350,7 +350,7 @@ class RegExpPlus extends InfiniteRepetitionQuantifier {
350350

351351
override string getAPrimaryQlClass() { result = "RegExpPlus" }
352352

353-
override predicate matchesEmptyString() { this.getAChild().matchesEmptyString() }
353+
override predicate isNullable() { this.getAChild().isNullable() }
354354
}
355355

356356
/**
@@ -367,7 +367,7 @@ class RegExpOpt extends RegExpQuantifier {
367367

368368
override string getAPrimaryQlClass() { result = "RegExpOpt" }
369369

370-
override predicate matchesEmptyString() { any() }
370+
override predicate isNullable() { any() }
371371
}
372372

373373
/**
@@ -407,9 +407,7 @@ class RegExpRange extends RegExpQuantifier {
407407
/** Gets the lower bound of the range. */
408408
int getLowerBound() { result = this.getLower().toInt() }
409409

410-
override predicate matchesEmptyString() {
411-
this.getAChild().matchesEmptyString() or this.getLowerBound() = 0
412-
}
410+
override predicate isNullable() { this.getAChild().isNullable() or this.getLowerBound() = 0 }
413411
}
414412

415413
/**
@@ -457,8 +455,8 @@ class RegExpSequence extends RegExpTerm, TRegExpSequence {
457455

458456
override string getAPrimaryQlClass() { result = "RegExpSequence" }
459457

460-
override predicate matchesEmptyString() {
461-
forall(RegExpTerm child | child = this.getAChild() | child.matchesEmptyString())
458+
override predicate isNullable() {
459+
forall(RegExpTerm child | child = this.getAChild() | child.isNullable())
462460
}
463461

464462
// Why can't we use concat(...) with language[monotonicAggregates] here instead?
@@ -540,7 +538,7 @@ class RegExpAlt extends RegExpTerm, TRegExpAlt {
540538

541539
override string getAPrimaryQlClass() { result = "RegExpAlt" }
542540

543-
override predicate matchesEmptyString() { this.getAChild().matchesEmptyString() }
541+
override predicate isNullable() { this.getAChild().isNullable() }
544542
}
545543

546544
class RegExpCharEscape = RegExpEscape;
@@ -616,7 +614,7 @@ class RegExpEscape extends RegExpNormalChar {
616614
class RegExpWordBoundary extends RegExpSpecialChar {
617615
RegExpWordBoundary() { this.getChar() = "\\b" }
618616

619-
override predicate matchesEmptyString() { none() }
617+
override predicate isNullable() { none() }
620618
}
621619

622620
/**
@@ -646,7 +644,7 @@ class RegExpCharacterClassEscape extends RegExpEscape {
646644

647645
override string getAPrimaryQlClass() { result = "RegExpCharacterClassEscape" }
648646

649-
override predicate matchesEmptyString() { none() }
647+
override predicate isNullable() { none() }
650648
}
651649

652650
/**
@@ -704,7 +702,7 @@ class RegExpCharacterClass extends RegExpTerm, TRegExpCharacterClass {
704702

705703
override string getAPrimaryQlClass() { result = "RegExpCharacterClass" }
706704

707-
override predicate matchesEmptyString() { none() }
705+
override predicate isNullable() { none() }
708706

709707
override string getAMatch() { not this.isInverted() and result = this.getAChild().getAMatch() }
710708
}
@@ -747,7 +745,7 @@ class RegExpCharacterRange extends RegExpTerm, TRegExpCharacterRange {
747745

748746
override string getAPrimaryQlClass() { result = "RegExpCharacterRange" }
749747

750-
override predicate matchesEmptyString() { none() }
748+
override predicate isNullable() { none() }
751749
}
752750

753751
/**
@@ -820,7 +818,7 @@ class RegExpConstant extends RegExpTerm {
820818

821819
override string getAPrimaryQlClass() { result = "RegExpConstant" }
822820

823-
override predicate matchesEmptyString() { none() }
821+
override predicate isNullable() { none() }
824822

825823
override string getAMatch() { result = this.getValue() }
826824
}
@@ -871,7 +869,7 @@ class RegExpGroup extends RegExpTerm, TRegExpGroup {
871869

872870
override string getAPrimaryQlClass() { result = "RegExpGroup" }
873871

874-
override predicate matchesEmptyString() { this.getAChild().matchesEmptyString() }
872+
override predicate isNullable() { this.getAChild().isNullable() }
875873

876874
override string getAMatch() { result = this.getAChild().getAMatch() }
877875
}
@@ -922,7 +920,7 @@ class RegExpDot extends RegExpSpecialChar {
922920

923921
override string getAPrimaryQlClass() { result = "RegExpDot" }
924922

925-
override predicate matchesEmptyString() { none() }
923+
override predicate isNullable() { none() }
926924
}
927925

928926
/**
@@ -954,7 +952,7 @@ class RegExpDollar extends RegExpAnchor {
954952

955953
override string getAPrimaryQlClass() { result = "RegExpDollar" }
956954

957-
override predicate matchesEmptyString() { any() }
955+
override predicate isNullable() { any() }
958956
}
959957

960958
/**
@@ -971,7 +969,7 @@ class RegExpCaret extends RegExpAnchor {
971969

972970
override string getAPrimaryQlClass() { result = "RegExpCaret" }
973971

974-
override predicate matchesEmptyString() { any() }
972+
override predicate isNullable() { any() }
975973
}
976974

977975
/**
@@ -990,7 +988,7 @@ class RegExpZeroWidthMatch extends RegExpGroup {
990988

991989
override string getAPrimaryQlClass() { result = "RegExpZeroWidthMatch" }
992990

993-
override predicate matchesEmptyString() { any() }
991+
override predicate isNullable() { any() }
994992
}
995993

996994
/**
@@ -1017,7 +1015,7 @@ class RegExpSubPattern extends RegExpZeroWidthMatch {
10171015
)
10181016
}
10191017

1020-
override predicate matchesEmptyString() { any() }
1018+
override predicate isNullable() { any() }
10211019
}
10221020

10231021
/**
@@ -1046,7 +1044,7 @@ class RegExpPositiveLookahead extends RegExpLookahead {
10461044

10471045
override string getAPrimaryQlClass() { result = "RegExpPositiveLookahead" }
10481046

1049-
override predicate matchesEmptyString() { any() }
1047+
override predicate isNullable() { any() }
10501048
}
10511049

10521050
/**
@@ -1143,7 +1141,7 @@ class RegExpBackRef extends RegExpTerm, TRegExpBackRef {
11431141

11441142
override string getAPrimaryQlClass() { result = "RegExpBackRef" }
11451143

1146-
override predicate matchesEmptyString() { this.getGroup().matchesEmptyString() }
1144+
override predicate isNullable() { this.getGroup().isNullable() }
11471145
}
11481146

11491147
/**

ruby/ql/lib/codeql/ruby/security/IncompleteMultiCharacterSanitizationQuery.qll

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,12 @@ private class DangerousPrefixSubstring extends string {
5353
*/
5454
private DangerousPrefix getADangerousMatchedPrefix(EmptyReplaceRegExpTerm t) {
5555
result = getADangerousMatchedPrefixSubstring(t) and
56-
not exists(EmptyReplaceRegExpTerm pred |
57-
pred = t.getPredecessor+() and not pred.matchesEmptyString()
58-
)
56+
not exists(EmptyReplaceRegExpTerm pred | pred = t.getPredecessor+() and not pred.isNullable())
5957
}
6058

6159
pragma[noinline]
6260
private DangerousPrefixSubstring getADangerousMatchedChar(EmptyReplaceRegExpTerm t) {
63-
t.matchesEmptyString() and result = ""
61+
t.isNullable() and result = ""
6462
or
6563
result = t.getAMatch()
6664
or
@@ -191,15 +189,15 @@ predicate hasResult(
191189
replace = regexp.getCall() and
192190
dangerous.getRootTerm() = regexp and
193191
// skip leading optional elements
194-
not dangerous.matchesEmptyString() and
192+
not dangerous.isNullable() and
195193
// only warn about the longest match
196194
prefix = max(string m | matchesDangerousPrefix(dangerous, m, kind) | m order by m.length(), m) and
197195
// only warn once per kind
198196
not exists(EmptyReplaceRegExpTerm other |
199197
other = dangerous.getAChild+() or other = dangerous.getPredecessor+()
200198
|
201199
matchesDangerousPrefix(other, _, kind) and
202-
not other.matchesEmptyString()
200+
not other.isNullable()
203201
) and
204202
not exists(RETV::RegExpCaret c | regexp = c.getRootTerm()) and
205203
not exists(RETV::RegExpDollar d | regexp = d.getRootTerm()) and

0 commit comments

Comments
 (0)