Skip to content

Commit a9eac19

Browse files
committed
Ruby: address review feedback
1 parent c7ba7fd commit a9eac19

File tree

3 files changed

+8
-10
lines changed

3 files changed

+8
-10
lines changed

ruby/ql/lib/change-notes/2022-03-25-deprecate-getStringOrSymbol.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
category: minorAnalysis
33
---
44
* Whereas `ConstantValue::getString()` previously returned both string and regular-expression values, it now returns only string values. The same applies to `ConstantValue::isString(value)`.
5-
* Regular-expression values can now be accessed with the new predicates `ConstantValue::getRegExp()`, `ConstantValue::isRegExp(value)`, and `ConstantValue::isRegExpWithFlags(value, flags).
5+
* Regular-expression values can now be accessed with the new predicates `ConstantValue::getRegExp()`, `ConstantValue::isRegExp(value)`, and `ConstantValue::isRegExpWithFlags(value, flags)`.

ruby/ql/lib/codeql/ruby/ast/Constant.qll

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ class ConstantValue extends TConstantValue {
7474
/** Gets the regexp value, if this is a regexp. */
7575
string getRegExp() { this.isRegExpWithFlags(result, _) }
7676

77-
/** Holds if this is the regexp value `/s/`. */
77+
/** Holds if this is the regexp value `/s/`, ignoring any flags. */
7878
predicate isRegExp(string s) { this.isRegExpWithFlags(s, _) }
7979

8080
/** Holds if this is the regexp value `/s/flags` . */
@@ -125,13 +125,13 @@ module ConstantValue {
125125
class ConstantStringlikeValue extends ConstantValue, TStringlike { }
126126

127127
/** A constant string value. */
128-
class ConstantStringValue extends ConstantValue, TString { }
128+
class ConstantStringValue extends ConstantStringlikeValue, TString { }
129129

130130
/** A constant symbol value. */
131-
class ConstantSymbolValue extends ConstantValue, TSymbol { }
131+
class ConstantSymbolValue extends ConstantStringlikeValue, TSymbol { }
132132

133133
/** A constant regexp value. */
134-
class ConstantRegExpValue extends ConstantValue, TRegExp { }
134+
class ConstantRegExpValue extends ConstantStringlikeValue, TRegExp { }
135135

136136
/** A constant Boolean value. */
137137
class ConstantBooleanValue extends ConstantValue, TBoolean { }

ruby/ql/test/library-tests/ast/escape_sequences/EscapeSequences.ql

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@ query predicate regexpEscapeSequenceComponents(RegExpEscapeSequenceComponent c,
1818
}
1919

2020
query predicate stringlikeLiterals(StringlikeLiteral l, string value, string kind) {
21-
value = l.getConstantValue().getString() and kind = "string"
22-
or
23-
value = l.getConstantValue().getSymbol() and kind = "symbol"
24-
or
25-
value = l.getConstantValue().getRegExp() and kind = "regexp"
21+
exists(ConstantValue v |
22+
v = l.getConstantValue() and value = v.getStringlikeValue() and kind = v.getValueType()
23+
)
2624
}

0 commit comments

Comments
 (0)