rspec/rules/S5334/python/rule.adoc

39 lines
714 B
Plaintext
Raw Normal View History

2020-06-30 12:50:28 +02:00
include::../description.adoc[]
== Noncompliant Code Example
2022-02-04 17:28:24 +01:00
[source,python]
2020-06-30 12:50:28 +02:00
----
from flask import request
@app.route('/')
def index():
module = request.args.get("module")
exec("import urllib%s as urllib" % module) # Noncompliant
----
== Compliant Solution
2022-02-04 17:28:24 +01:00
[source,python]
2020-06-30 12:50:28 +02:00
----
from flask import request
@app.route('/')
def index():
module = request.args.get("module")
exec("import urllib%d as urllib" % int(module)) # Compliant; module is safely cast to an integer
----
include::../see.adoc[]
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
include::../message.adoc[]
include::../highlighting.adoc[]
endif::env-github,rspecator-view[]