Marco Borgeaud 8209548e54
Diff blocks: fix incorrect use for python (#2795)
Improvement identified in #2790.

Add a prefix to the diff-id when it is used multiple times in different
"how to fix it in XYZ" sections to avoid ambiguity and pedantically
follow the spec:

> A single and unique diff-id should be used only once for each type of
code example as shown in the description of a rule.

Obvious typos around `diff-type` were fixed.

An obvious extra use of diff blocks was removed.
2023-08-21 15:22:49 +02:00

40 lines
741 B
Plaintext

== How to fix it in Flask
=== Code examples
include::../../common/fix/code-rationale.adoc[]
==== Noncompliant code example
[source,python,diff-id=11,diff-type=noncompliant]
----
from flask import Flask, redirect
app = Flask("example")
@app.route("/redirecting")
def redirecting():
url = request.args["url"]
return redirect(url) # Noncompliant
----
==== Compliant solution
[source,python,diff-id=11,diff-type=compliant]
----
from flask import Flask, redirect, url_for
app = Flask("example")
@app.route("/redirecting")
def redirecting():
url = request.args["url"]
return redirect(url_for(url))
----
include::../../common/fix/how-does-this-work.adoc[]
=== Pitfalls
include::../../common/pitfalls/starts-with.adoc[]