Fix plus test for unicode characters in custom query name, closes #558

This commit is contained in:
Simon Willison 2019-07-13 19:49:24 -07:00
commit 90d4f497f9
3 changed files with 25 additions and 16 deletions

View file

@ -45,9 +45,10 @@ class Request:
@property @property
def path(self): def path(self):
return ( if "raw_path" in self.scope:
self.scope.get("raw_path", self.scope["path"].encode("latin-1")) return self.scope["raw_path"].decode("latin-1")
).decode("latin-1") else:
return self.scope["path"].decode("utf-8")
@property @property
def query_string(self): def query_string(self):

View file

@ -12,7 +12,7 @@ import sys
import string import string
import tempfile import tempfile
import time import time
from urllib.parse import unquote from urllib.parse import unquote, quote
# This temp file is used by one of the plugin config tests # This temp file is used by one of the plugin config tests
@ -49,18 +49,20 @@ class TestClient:
if "?" in path: if "?" in path:
path, _, query_string = path.partition("?") path, _, query_string = path.partition("?")
query_string = query_string.encode("utf8") query_string = query_string.encode("utf8")
instance = ApplicationCommunicator( if "%" in path:
self.asgi_app, raw_path = path.encode("latin-1")
{ else:
"type": "http", raw_path = quote(path, safe="/:,").encode("latin-1")
"http_version": "1.0", scope = {
"method": method, "type": "http",
"path": unquote(path), "http_version": "1.0",
"raw_path": path.encode("ascii"), "method": method,
"query_string": query_string, "path": unquote(path),
"headers": [[b"host", b"localhost"]], "raw_path": raw_path,
}, "query_string": query_string,
) "headers": [[b"host", b"localhost"]],
}
instance = ApplicationCommunicator(self.asgi_app, scope)
await instance.send_input({"type": "http.request"}) await instance.send_input({"type": "http.request"})
# First message back should be response.start with headers and status # First message back should be response.start with headers and status
messages = [] messages = []
@ -291,6 +293,7 @@ METADATA = {
}, },
}, },
"queries": { "queries": {
"𝐜𝐢𝐭𝐢𝐞𝐬": "select id, name from facet_cities order by id limit 1;",
"pragma_cache_size": "PRAGMA cache_size;", "pragma_cache_size": "PRAGMA cache_size;",
"neighborhood_search": { "neighborhood_search": {
"sql": """ "sql": """

View file

@ -1613,6 +1613,11 @@ def test_infinity_returned_as_invalid_json_if_requested(app_client):
] == response.json ] == response.json
def test_custom_query_with_unicode_characters(app_client):
response = app_client.get("/fixtures/𝐜𝐢𝐭𝐢𝐞𝐬.json?_shape=array")
assert [{"id": 1, "name": "San Francisco"}] == response.json
def test_trace(app_client): def test_trace(app_client):
response = app_client.get("/fixtures/simple_primary_key.json?_trace=1") response = app_client.get("/fixtures/simple_primary_key.json?_trace=1")
data = response.json data = response.json