Skip to content

Commit 2e43032

Browse files
RasmusWLtausbn
andauthored
Python: Refactor argument matching to use set literals
Co-authored-by: Taus <tausbn@github.com>
1 parent d26a89b commit 2e43032

File tree

1 file changed

+5
-22
lines changed
  • python/ql/src/experimental/semmle/python/frameworks

1 file changed

+5
-22
lines changed

python/ql/src/experimental/semmle/python/frameworks/Flask.qll

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -157,14 +157,7 @@ private module Flask {
157157
}
158158

159159
override DataFlow::Node getUrlPatternArg() {
160-
exists(ControlFlowNode pattern_arg |
161-
(
162-
pattern_arg = call.getArg(0)
163-
or
164-
pattern_arg = call.getArgByName("rule")
165-
) and
166-
result.asCfgNode() = pattern_arg
167-
)
160+
result.asCfgNode() in [call.getArg(0), call.getArgByName("rule")]
168161
}
169162

170163
override Function getARouteHandler() { result.getADecorator() = call.getNode() }
@@ -184,23 +177,13 @@ private module Flask {
184177
}
185178

186179
override DataFlow::Node getUrlPatternArg() {
187-
exists(ControlFlowNode pattern_arg |
188-
(
189-
pattern_arg = call.getArg(0)
190-
or
191-
pattern_arg = call.getArgByName("rule")
192-
) and
193-
result.asCfgNode() = pattern_arg
194-
)
180+
result.asCfgNode() in [call.getArg(0), call.getArgByName("rule")]
195181
}
196182

197183
override Function getARouteHandler() {
198-
exists(ControlFlowNode view_func_arg, DataFlow::Node func_src |
199-
view_func_arg = call.getArg(2)
200-
or
201-
view_func_arg = call.getArgByName("view_func")
202-
|
203-
DataFlow::localFlow(func_src, any(DataFlow::Node dest | dest.asCfgNode() = view_func_arg)) and
184+
exists(DataFlow::Node view_func_arg, DataFlow::Node func_src |
185+
view_func_arg.asCfgNode() in [call.getArg(2), call.getArgByName("view_func")] and
186+
DataFlow::localFlow(func_src, view_func_arg) and
204187
func_src.asExpr().(CallableExpr) = result.getDefinition()
205188
)
206189
}

0 commit comments

Comments
 (0)