Skip to content

Commit 26c048a

Browse files
Minor refactoring
1 parent e2e4642 commit 26c048a

File tree

1 file changed

+10
-6
lines changed
  • csharp/ql/lib/semmle/code/csharp/frameworks

1 file changed

+10
-6
lines changed

csharp/ql/lib/semmle/code/csharp/frameworks/Razor.qll

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,12 +85,13 @@ class RazorPageClass extends Class {
8585
}
8686

8787
private class ViewCallJumpNode extends DataFlow::NonLocalJumpNode {
88-
ViewCall vc;
8988
RazorPageClass rp;
9089

9190
ViewCallJumpNode() {
92-
viewCallRefersToPage(vc, rp) and
93-
this.asExpr() = vc.getModelArgument()
91+
exists(ViewCall vc |
92+
viewCallRefersToPage(vc, rp) and
93+
this.asExpr() = vc.getModelArgument()
94+
)
9495
}
9596

9697
override DataFlow::Node getAJumpSuccessor(boolean preservesValue) {
@@ -108,8 +109,11 @@ private predicate viewCallRefersToPage(ViewCall vc, RazorPageClass rp) {
108109
viewCallRefersToPageRelative(vc, rp)
109110
}
110111

112+
bindingset[path]
113+
private string stripTilde(string path) { result = path.regexpReplaceAll("^~/", "/") }
114+
111115
private predicate viewCallRefersToPageAbsolute(ViewCall vc, RazorPageClass rp) {
112-
["/", ""] + vc.getNameArgument() = ["", "~"] + rp.getSourceFilepath()
116+
["/", ""] + stripTilde(vc.getNameArgument()) = rp.getSourceFilepath()
113117
}
114118

115119
private predicate viewCallRefersToPageRelative(ViewCall vc, RazorPageClass rp) {
@@ -119,7 +123,7 @@ private predicate viewCallRefersToPageRelative(ViewCall vc, RazorPageClass rp) {
119123
private predicate matchesViewCallWithIndex(ViewCall vc, RazorPageClass rp, int i) {
120124
exists(RelativeViewCallFilepath fp |
121125
fp.hasViewCallWithIndex(vc, i) and
122-
fp.getNormalizedPath() = ["", "~"] + rp.getSourceFilepath()
126+
fp.getNormalizedPath() = rp.getSourceFilepath()
123127
)
124128
}
125129

@@ -183,7 +187,7 @@ private class RelativeViewCallFilepath extends NormalizableFilepath {
183187
else sub1 = sub2
184188
) and
185189
sub0 = sub1.replaceAll("{0}", vc_.getActionName()) and
186-
this = sub0
190+
this = stripTilde(sub0)
187191
)
188192
}
189193

0 commit comments

Comments
 (0)