Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 81a42b7

Browse files
committed
Python: Model flask.Response
I think I'll rework how we model content-type, since what we _actually_ want to know is the mimetype
1 parent 1f99bbf commit 81a42b7

2 files changed

Lines changed: 10 additions & 13 deletions

File tree

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
| response_test.py:92:12:92:79 | ControlFlowNode for Response() | Unexpected result: contentType=text/plain; charset=utf-8 |
2+
| response_test.py:99:12:99:101 | ControlFlowNode for Response() | Unexpected result: contentType=text/plain; charset=utf-8 |
3+
| response_test.py:114:12:114:118 | ControlFlowNode for Response() | Unexpected result: contentType=text/plain; charset=utf-8 |

python/ql/test/experimental/library-tests/frameworks/flask/response_test.py

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def html3(): # $routeHandler
3131

3232
@app.route("/html4") # $routeSetup="/html4"
3333
def html4(): # $routeHandler
34-
resp = Response("<h1>hello</h1>") # $f-:HttpResponse $f-:contentType=text/html $f-:responseBody="<h1>hello</h1>"
34+
resp = Response("<h1>hello</h1>") # $HttpResponse $contentType=text/html $responseBody="<h1>hello</h1>"
3535
return resp
3636

3737

@@ -83,49 +83,43 @@ def response_modification2(): # $routeHandler
8383

8484
@app.route("/content-type/Response1") # $routeSetup="/content-type/Response1"
8585
def Response1(): # $routeHandler
86-
resp = Response("<h1>hello</h1>", mimetype="text/plain") # $f-:HttpResponse $f-:contentType=text/plain $f-:responseBody="<h1>hello</h1>"
86+
resp = Response("<h1>hello</h1>", mimetype="text/plain") # $HttpResponse $contentType=text/plain $responseBody="<h1>hello</h1>"
8787
return resp
8888

8989

9090
@app.route("/content-type/Response2") # $routeSetup="/content-type/Response2"
9191
def Response2(): # $routeHandler
92-
resp = Response("<h1>hello</h1>", content_type="text/plain; charset=utf-8") # $f-:HttpResponse $f-:contentType=text/plain $f-:responseBody="<h1>hello</h1>"
92+
resp = Response("<h1>hello</h1>", content_type="text/plain; charset=utf-8") # $HttpResponse $f-:contentType=text/plain $responseBody="<h1>hello</h1>"
9393
return resp
9494

9595

9696
@app.route("/content-type/Response3") # $routeSetup="/content-type/Response3"
9797
def Response3(): # $routeHandler
9898
# content_type argument takes priority (and result is text/plain)
99-
resp = Response(
100-
"<h1>hello</h1>", content_type="text/plain; charset=utf-8", mimetype="text/html"
101-
) # $f-:HttpResponse $f-:contentType=text/plain $f-:responseBody="<h1>hello</h1>"
99+
resp = Response("<h1>hello</h1>", content_type="text/plain; charset=utf-8", mimetype="text/html") # $HttpResponse $f-:contentType=text/plain $responseBody="<h1>hello</h1>"
102100
return resp
103101

104102

105103
@app.route("/content-type/Response4") # $routeSetup="/content-type/Response4"
106104
def Response4(): # $routeHandler
107105
# note: capitalization of Content-Type does not matter
108-
resp = Response("<h1>hello</h1>", headers={"Content-TYPE": "text/plain"}) # $f-:HttpResponse $f-:contentType=text/plain $f-:responseBody="<h1>hello</h1>"
106+
resp = Response("<h1>hello</h1>", headers={"Content-TYPE": "text/plain"}) # $HttpResponse $f+:contentType=text/html $f-:contentType=text/plain $responseBody="<h1>hello</h1>"
109107
return resp
110108

111109

112110
@app.route("/content-type/Response5") # $routeSetup="/content-type/Response5"
113111
def Response5(): # $routeHandler
114112
# content_type argument takes priority (and result is text/plain)
115113
# note: capitalization of Content-Type does not matter
116-
resp = Response(
117-
"<h1>hello</h1>", headers={"Content-TYPE": "text/html"}, content_type="text/plain; charset=utf-8"
118-
) # $f-:HttpResponse $f-:contentType=text/plain $f-:responseBody="<h1>hello</h1>"
114+
resp = Response("<h1>hello</h1>", headers={"Content-TYPE": "text/html"}, content_type="text/plain; charset=utf-8") # $HttpResponse $f-:contentType=text/plain $responseBody="<h1>hello</h1>"
119115
return resp
120116

121117

122118
@app.route("/content-type/Response6") # $routeSetup="/content-type/Response6"
123119
def Response6(): # $routeHandler
124120
# mimetype argument takes priority over header (and result is text/plain)
125121
# note: capitalization of Content-Type does not matter
126-
resp = Response(
127-
"<h1>hello</h1>", headers={"Content-TYPE": "text/html"}, mimetype="text/plain"
128-
) # $f-:HttpResponse $f-:contentType=text/plain $f-:responseBody="<h1>hello</h1>"
122+
resp = Response("<h1>hello</h1>", headers={"Content-TYPE": "text/html"}, mimetype="text/plain") # $HttpResponse $contentType=text/plain $responseBody="<h1>hello</h1>"
129123
return resp
130124

131125

0 commit comments

Comments
 (0)