Skip to content

Commit ee106cc

Browse files
author
Esben Sparre Andreasen
committed
JS: simplify asExpr().getStringValue() calls
1 parent aab1785 commit ee106cc

File tree

6 files changed

+12
-12
lines changed

6 files changed

+12
-12
lines changed

javascript/ql/src/Security/CWE-798/HardcodedCredentials.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ where
2222
// use source value in message if it's available
2323
if source.getNode().asExpr() instanceof ConstantString
2424
then
25-
value = "The hard-coded value \"" + source.getNode().asExpr().getStringValue() +
25+
value = "The hard-coded value \"" + source.getNode().getStringValue() +
2626
"\""
2727
else value = "This hard-coded value"
2828
select source.getNode(), source, sink, value + " is used as $@.", sink.getNode(),

javascript/ql/src/semmle/javascript/Closure.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ module Closure {
5656
ClosureNamespaceRef::Range {
5757
DefaultNamespaceRef() { this = DataFlow::globalVarRef("goog").getAMethodCall() }
5858

59-
override string getClosureNamespace() { result = getArgument(0).asExpr().getStringValue() }
59+
override string getClosureNamespace() { result = getArgument(0).getStringValue() }
6060
}
6161

6262
/**

javascript/ql/src/semmle/javascript/StandardLibrary.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class CallToObjectDefineProperty extends DataFlow::MethodCallNode {
1717
DataFlow::Node getBaseObject() { result = getArgument(0) }
1818

1919
/** Gets the name of the property being defined, if it can be determined. */
20-
string getPropertyName() { result = getArgument(1).asExpr().getStringValue() }
20+
string getPropertyName() { result = getArgument(1).getStringValue() }
2121

2222
/** Gets the data flow node denoting the descriptor of the property being defined. */
2323
DataFlow::Node getPropertyDescriptor() { result = getArgument(2) }

javascript/ql/src/semmle/javascript/frameworks/Electron.qll

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ module Electron {
116116
Process getProcess() { result = process }
117117

118118
/** Gets the name of the channel the callback is listening on. */
119-
string getChannelName() { result = channel.asExpr().getStringValue() }
119+
string getChannelName() { result = channel.getStringValue() }
120120

121121
/** Gets the data flow node containing the message received by the callback. */
122122
DataFlow::Node getMessage() { result = getParameter(1) }
@@ -156,7 +156,7 @@ module Electron {
156156

157157
override Process getProcess() { result = process }
158158

159-
override string getChannelName() { result = channel.asExpr().getStringValue() }
159+
override string getChannelName() { result = channel.getStringValue() }
160160
}
161161

162162
/**
@@ -186,7 +186,7 @@ module Electron {
186186

187187
override Process getProcess() { result = callback.getProcess() }
188188

189-
override string getChannelName() { result = channel.asExpr().getStringValue() }
189+
override string getChannelName() { result = channel.getStringValue() }
190190
}
191191

192192
/**
@@ -221,7 +221,7 @@ module Electron {
221221

222222
override Process getProcess() { result = Process::main() }
223223

224-
override string getChannelName() { result = channel.asExpr().getStringValue() }
224+
override string getChannelName() { result = channel.getStringValue() }
225225
}
226226

227227
/**

javascript/ql/src/semmle/javascript/security/dataflow/TaintedPathCustomizations.qll

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -229,11 +229,11 @@ module TaintedPath {
229229
* Holds if `node` is a prefix of the string `../`.
230230
*/
231231
private predicate isDotDotSlashPrefix(DataFlow::Node node) {
232-
node.asExpr().getStringValue() + any(string s) = "../"
232+
node.getStringValue() + any(string s) = "../"
233233
or
234234
// ".." + path.sep
235235
exists(StringOps::Concatenation conc | node = conc |
236-
conc.getOperand(0).asExpr().getStringValue() = ".." and
236+
conc.getOperand(0).getStringValue() = ".." and
237237
conc.getOperand(1).getALocalSource() = DataFlow::moduleMember("path", "sep") and
238238
conc.getNumOperand() = 2
239239
)
@@ -277,7 +277,7 @@ module TaintedPath {
277277
this = startsWith and
278278
not isDotDotSlashPrefix(startsWith.getSubstring()) and
279279
// do not confuse this with a simple isAbsolute() check
280-
not startsWith.getSubstring().asExpr().getStringValue() = "/"
280+
not startsWith.getSubstring().getStringValue() = "/"
281281
}
282282

283283
override predicate blocks(boolean outcome, Expr e, DataFlow::FlowLabel label) {
@@ -308,7 +308,7 @@ module TaintedPath {
308308
)
309309
or
310310
exists(StringOps::StartsWith startsWith, string substring | this = startsWith |
311-
startsWith.getSubstring().asExpr().getStringValue() = "/" + substring and
311+
startsWith.getSubstring().getStringValue() = "/" + substring and
312312
operand = startsWith.getBaseString() and
313313
polarity = startsWith.getPolarity() and
314314
if substring = "" then negatable = true else negatable = false

javascript/ql/test/library-tests/StringConcatenation/ContainsTwo.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import javascript
22

33
// Select all expressions whose string value contains the word "two"
44
predicate containsTwo(DataFlow::Node node) {
5-
node.asExpr().getStringValue().regexpMatch(".*two.*")
5+
node.getStringValue().regexpMatch(".*two.*")
66
or
77
containsTwo(node.getAPredecessor())
88
or

0 commit comments

Comments
 (0)