Skip to content

Commit

Permalink
Quote path component before logging (#724)
Browse files Browse the repository at this point in the history
* Quote path component before logging

* Linting
  • Loading branch information
tomchristie authored Jul 28, 2020
1 parent 789e2f1 commit 895807f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
7 changes: 4 additions & 3 deletions uvicorn/logging.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import http
import logging
import sys
import urllib
from copy import copy

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

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

def get_full_path(self, scope):
path = scope.get("root_path", "") + scope["path"]
query_string = scope.get("query_string", b"").decode("ascii")
if query_string:
return path + "?" + query_string
return path
return urllib.parse.quote(path) + "?" + query_string
return urllib.parse.quote(path)

def get_status_code(self, record):
status_code = record.__dict__["status_code"]
Expand Down
5 changes: 4 additions & 1 deletion uvicorn/protocols/utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import socket
import urllib


def get_remote_addr(transport):
Expand Down Expand Up @@ -49,7 +50,9 @@ def get_client_addr(scope):


def get_path_with_query_string(scope):
path_with_query_string = scope.get("root_path", "") + scope["path"]
path_with_query_string = urllib.parse.quote(
scope.get("root_path", "") + scope["path"]
)
if scope["query_string"]:
path_with_query_string = "{}?{}".format(
path_with_query_string, scope["query_string"].decode("ascii")
Expand Down

0 comments on commit 895807f

Please sign in to comment.