Skip to content

Commit

Permalink
Modify rule S5146: Fix invalid Python sample (#2239)
Browse files Browse the repository at this point in the history
I couldn't get Sonarcloud to trigger this issue using the provided
noncompliant code example.

I think the code examples as written end up being circular because the
local function 'redirect()' will call itself rather than the imported
'redirect()' function of the same name. The fix is to change the local
function name to be redirecting(). I changed the API endpoint name as
well so that it matched. Once I had made this change, the noncompliant
code example did lead to Sonarcloud spotting the issue.

## Review

A dedicated reviewer checked the rule description successfully for:

- [x] logical errors and incorrect information
- [x] information gaps and missing content
- [x] text style and tone
- [x] PR summary and labels follow [the
guidelines](https://github.com/SonarSource/rspec/#to-modify-an-existing-rule)
  • Loading branch information
1 parent bb6f206 commit 151ed01
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions rules/S5146/python/how-to-fix-it/flask.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ from flask import Flask, redirect
app = Flask("example")
@app.route("/redirect")
def redirect():
@app.route("/redirecting")
def redirecting():
url = request.args["url"]
return redirect(url) # Noncompliant
----
Expand All @@ -26,8 +26,8 @@ from flask import Flask, redirect, url_for
app = Flask("example")
@app.route("/redirect")
def redirect():
@app.route("/redirecting")
def redirecting():
url = request.args["url"]
return redirect(url_for(url))
----
Expand Down

0 comments on commit 151ed01

Please sign in to comment.