@@ -105,34 +105,45 @@ module Sinatra {
105
105
* Gets the template file referred to by `erbCall`.
106
106
* This works on the AST level to avoid non-monotonic reecursion in `ErbLocalsHashSyntheticGlobal`.
107
107
*/
108
+ pragma [ nomagic]
108
109
private ErbFile getTemplateFile ( MethodCall erbCall ) {
109
110
erbCall .getMethodName ( ) = "erb" and
110
111
result .getTemplateName ( ) = erbCall .getArgument ( 0 ) .getConstantValue ( ) .getStringlikeValue ( ) and
111
112
result .getRelativePath ( ) .matches ( "%views/%" )
112
113
}
113
114
115
+ pragma [ nomagic]
116
+ private predicate erbCallAtLocation ( MethodCall erbCall , ErbFile erbFile , Location l ) {
117
+ erbCall .getMethodName ( ) = "erb" and
118
+ erbFile = getTemplateFile ( erbCall ) and
119
+ l = erbCall .getLocation ( )
120
+ }
121
+
114
122
/**
115
123
* Like `Location.toString`, but displays the relative path rather than the full path.
116
124
*/
125
+ bindingset [ loc]
126
+ pragma [ inline_late]
117
127
private string locationRelativePathToString ( Location loc ) {
118
128
result =
119
129
loc .getFile ( ) .getRelativePath ( ) + "@" + loc .getStartLine ( ) + ":" + loc .getStartColumn ( ) + ":" +
120
130
loc .getEndLine ( ) + ":" + loc .getEndColumn ( )
121
131
}
122
132
123
133
/**
124
- * A synthetic global representing the hash of local variables passed to an ERB template.
134
+ * A synthetic global representing the hash of local variables passed to an ERB template.
125
135
*/
126
136
class ErbLocalsHashSyntheticGlobal extends SummaryComponent:: SyntheticGlobal {
127
137
private string id ;
128
138
private MethodCall erbCall ;
129
139
private ErbFile erbFile ;
130
140
131
141
ErbLocalsHashSyntheticGlobal ( ) {
132
- this = "SinatraErbLocalsHash(" + id + ")" and
133
- id = erbFile .getRelativePath ( ) + "," + locationRelativePathToString ( erbCall .getLocation ( ) ) and
134
- erbCall .getMethodName ( ) = "erb" and
135
- erbFile = getTemplateFile ( erbCall )
142
+ exists ( Location l |
143
+ erbCallAtLocation ( erbCall , erbFile , l ) and
144
+ id = erbFile .getRelativePath ( ) + "," + locationRelativePathToString ( l ) and
145
+ this = "SinatraErbLocalsHash(" + id + ")"
146
+ )
136
147
}
137
148
138
149
/**
0 commit comments