Skip to content

Commit 895807f

Browse files
authored
Quote path component before logging (#724)
* Quote path component before logging * Linting
1 parent 789e2f1 commit 895807f

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

uvicorn/logging.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import http
22
import logging
33
import sys
4+
import urllib
45
from copy import copy
56

67
import click
@@ -77,14 +78,14 @@ def get_client_addr(self, scope):
7778
return "%s:%d" % (client[0], client[1])
7879

7980
def get_path(self, scope):
80-
return scope.get("root_path", "") + scope["path"]
81+
return urllib.parse.quote(scope.get("root_path", "") + scope["path"])
8182

8283
def get_full_path(self, scope):
8384
path = scope.get("root_path", "") + scope["path"]
8485
query_string = scope.get("query_string", b"").decode("ascii")
8586
if query_string:
86-
return path + "?" + query_string
87-
return path
87+
return urllib.parse.quote(path) + "?" + query_string
88+
return urllib.parse.quote(path)
8889

8990
def get_status_code(self, record):
9091
status_code = record.__dict__["status_code"]

uvicorn/protocols/utils.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import socket
2+
import urllib
23

34

45
def get_remote_addr(transport):
@@ -49,7 +50,9 @@ def get_client_addr(scope):
4950

5051

5152
def get_path_with_query_string(scope):
52-
path_with_query_string = scope.get("root_path", "") + scope["path"]
53+
path_with_query_string = urllib.parse.quote(
54+
scope.get("root_path", "") + scope["path"]
55+
)
5356
if scope["query_string"]:
5457
path_with_query_string = "{}?{}".format(
5558
path_with_query_string, scope["query_string"].decode("ascii")

0 commit comments

Comments
 (0)