Skip to content

Commit 8bdc05d

Browse files
committed
getValueText -> getConstantValue
1 parent 4172871 commit 8bdc05d

File tree

1 file changed

+53
-27
lines changed

1 file changed

+53
-27
lines changed

ruby/ql/lib/codeql/ruby/frameworks/ActionDispatch.qll

Lines changed: 53 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -207,15 +207,15 @@ module ActionDispatch {
207207
override Location getLocation() { result = call.getLocation() }
208208

209209
override string getPathComponent() {
210-
result = call.getKeywordArgument("path").(StringlikeLiteral).getValueText()
210+
result = call.getKeywordArgument("path").getConstantValue().getStringOrSymbol()
211211
or
212212
not exists(call.getKeywordArgument("path")) and
213-
result = call.getArgument(0).(StringlikeLiteral).getValueText()
213+
result = call.getArgument(0).getConstantValue().getStringOrSymbol()
214214
}
215215

216216
override string getControllerComponent() {
217-
result = call.getKeywordArgument("controller").getValueText() or
218-
result = call.getKeywordArgument("module").getValueText()
217+
result = call.getKeywordArgument("controller").getConstantValue().getStringOrSymbol() or
218+
result = call.getKeywordArgument("module").getConstantValue().getStringOrSymbol()
219219
}
220220
}
221221

@@ -244,7 +244,9 @@ module ActionDispatch {
244244
MethodCall getDefiningMethodCall() { result = call }
245245

246246
override string getPathComponent() {
247-
exists(string resource | resource = call.getArgument(0).getValueText() |
247+
exists(string resource |
248+
resource = call.getArgument(0).getConstantValue().getStringOrSymbol()
249+
|
248250
result = resource + "/:" + singularize(resource) + "_id"
249251
)
250252
}
@@ -306,7 +308,9 @@ module ActionDispatch {
306308

307309
override string getControllerComponent() { result = this.getNamespace() }
308310

309-
private string getNamespace() { result = call.getArgument(0).getValueText() }
311+
private string getNamespace() {
312+
result = call.getArgument(0).getConstantValue().getStringOrSymbol()
313+
}
310314

311315
override string toString() { result = call.toString() }
312316

@@ -504,11 +508,11 @@ module ActionDispatch {
504508
override RouteBlock getParentBlock() { result = parentBlock }
505509

506510
override string getLastPathComponent() {
507-
result = method.getArgument(0).(StringlikeLiteral).getValueText()
511+
result = method.getArgument(0).getConstantValue().getStringOrSymbol()
508512
}
509513

510514
override string getLastControllerComponent() {
511-
result = method.getKeywordArgument("controller").getValueText()
515+
result = method.getKeywordArgument("controller").getConstantValue().getStringOrSymbol()
512516
or
513517
not exists(method.getKeywordArgument("controller")) and
514518
(
@@ -532,15 +536,15 @@ module ActionDispatch {
532536
}
533537

534538
private string getActionString() {
535-
result = method.getKeywordArgument("to").(StringlikeLiteral).getValueText()
539+
result = method.getKeywordArgument("to").getConstantValue().getStringOrSymbol()
536540
or
537541
method.getKeywordArgument("to").(MethodCall).getMethodName() = "redirect" and
538542
result = "<redirect>#<redirect>"
539543
}
540544

541545
override string getAction() {
542546
// get "/photos", action: "index"
543-
result = method.getKeywordArgument("action").getValueText()
547+
result = method.getKeywordArgument("action").getConstantValue().getStringOrSymbol()
544548
or
545549
not exists(method.getKeywordArgument("action")) and
546550
(
@@ -555,7 +559,7 @@ module ActionDispatch {
555559
or
556560
// get :some_action
557561
not exists(this.getActionString()) and
558-
result = method.getArgument(0).(StringlikeLiteral).getValueText()
562+
result = method.getArgument(0).getConstantValue().getStringOrSymbol()
559563
)
560564
}
561565

@@ -602,7 +606,7 @@ module ActionDispatch {
602606

603607
ResourcesRoute() {
604608
this = TResourcesRoute(parent, method, action) and
605-
resource = method.getArgument(0).(StringlikeLiteral).getValueText() and
609+
resource = method.getArgument(0).getConstantValue().getStringOrSymbol() and
606610
isDefaultResourceRoute(resource, httpMethod, pathComponent, action)
607611
}
608612

@@ -612,7 +616,9 @@ module ActionDispatch {
612616

613617
override string getLastPathComponent() { result = pathComponent }
614618

615-
override string getLastControllerComponent() { result = method.getArgument(0).getValueText() }
619+
override string getLastControllerComponent() {
620+
result = method.getArgument(0).getConstantValue().getStringOrSymbol()
621+
}
616622

617623
override string getAction() { result = action }
618624

@@ -637,7 +643,7 @@ module ActionDispatch {
637643

638644
SingularResourceRoute() {
639645
this = TResourceRoute(parent, method, action) and
640-
resource = method.getArgument(0).(StringlikeLiteral).getValueText() and
646+
resource = method.getArgument(0).getConstantValue().getStringOrSymbol() and
641647
isDefaultSingularResourceRoute(resource, httpMethod, pathComponent, action)
642648
}
643649

@@ -647,7 +653,9 @@ module ActionDispatch {
647653

648654
override string getLastPathComponent() { result = pathComponent }
649655

650-
override string getLastControllerComponent() { result = method.getArgument(0).getValueText() }
656+
override string getLastControllerComponent() {
657+
result = method.getArgument(0).getConstantValue().getStringOrSymbol()
658+
}
651659

652660
override string getAction() { result = action }
653661

@@ -676,25 +684,39 @@ module ActionDispatch {
676684
override RouteBlock getParentBlock() { result = parent }
677685

678686
override string getLastPathComponent() {
679-
result = method.getArgument(0).(StringlikeLiteral).getValueText() or
680-
result = method.getArgument(0).(Pair).getKey().getValueText()
687+
result = method.getArgument(0).getConstantValue().getStringOrSymbol() or
688+
result = method.getArgument(0).(Pair).getKey().getConstantValue().getStringOrSymbol()
681689
}
682690

683691
override string getLastControllerComponent() {
684-
result = extractController(method.getKeywordArgument("to").getValueText()) or
685-
result = method.getKeywordArgument("controller").getValueText() or
686-
result = extractController(method.getArgument(0).(Pair).getValue().getValueText())
692+
result =
693+
extractController(method.getKeywordArgument("to").getConstantValue().getStringOrSymbol()) or
694+
result = method.getKeywordArgument("controller").getConstantValue().getStringOrSymbol() or
695+
result =
696+
extractController(method
697+
.getArgument(0)
698+
.(Pair)
699+
.getValue()
700+
.getConstantValue()
701+
.getStringOrSymbol())
687702
}
688703

689704
override string getHTTPMethod() {
690-
result = method.getKeywordArgument("via").(StringlikeLiteral).getValueText() or
691-
result = method.getKeywordArgument("via").(ArrayLiteral).getElement(_).getValueText()
705+
result = method.getKeywordArgument("via").getConstantValue().getStringOrSymbol() or
706+
result =
707+
method
708+
.getKeywordArgument("via")
709+
.(ArrayLiteral)
710+
.getElement(_)
711+
.getConstantValue()
712+
.getStringOrSymbol()
692713
}
693714

694715
override string getAction() {
695-
result = extractAction(method.getKeywordArgument("to").getValueText()) or
696-
result = method.getKeywordArgument("action").getValueText() or
697-
result = extractAction(method.getArgument(0).(Pair).getValue().getValueText())
716+
result = extractAction(method.getKeywordArgument("to").getConstantValue().getStringOrSymbol()) or
717+
result = method.getKeywordArgument("action").getConstantValue().getStringOrSymbol() or
718+
result =
719+
extractAction(method.getArgument(0).(Pair).getValue().getConstantValue().getStringOrSymbol())
698720
}
699721
}
700722

@@ -710,15 +732,19 @@ module ActionDispatch {
710732
not exists(m.getKeywordArgument("only"))
711733
or
712734
exists(Expr only | only = m.getKeywordArgument("only") |
713-
[only.(ArrayLiteral).getElement(_), only.(StringlikeLiteral)].getValueText() = action
735+
[only.(ArrayLiteral).getElement(_), only.(StringlikeLiteral)]
736+
.getConstantValue()
737+
.getStringOrSymbol() = action
714738
)
715739
) and
716740
// Respect the `except` keyword argument, which removes actions from the default set.
717741
(
718742
not exists(m.getKeywordArgument("except"))
719743
or
720744
exists(Expr except | except = m.getKeywordArgument("except") |
721-
[except.(ArrayLiteral).getElement(_), except.(StringlikeLiteral)].getValueText() != action
745+
[except.(ArrayLiteral).getElement(_), except.(StringlikeLiteral)]
746+
.getConstantValue()
747+
.getStringOrSymbol() != action
722748
)
723749
)
724750
}

0 commit comments

Comments
 (0)