Skip to content

Commit

Permalink
adds quote of path to adhere to PEP3333
Browse files Browse the repository at this point in the history
Signed-off-by: Kevin Griffin <[email protected]>
  • Loading branch information
m00sey committed Jul 10, 2024
1 parent 9f055be commit 0022d2b
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/hio/core/http/serving.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import datetime
import mimetypes

from urllib.parse import urlsplit, unquote
from urllib.parse import urlsplit, unquote, quote
from contextlib import contextmanager

from ... import help
Expand Down Expand Up @@ -725,7 +725,7 @@ def buildEnviron(self, requestant):
environ['SERVER_PORT'] = str(self.servant.eha[1]) # 8888
environ['SERVER_PROTOCOL'] = "HTTP/{0}.{1}".format(*requestant.version) # used by request http/1.1
environ['SCRIPT_NAME'] = u''
environ['PATH_INFO'] = requestant.path # /hello?name=john
environ['PATH_INFO'] = quote(requestant.path) # /hello?name=john

# Optional CGI variables
environ['QUERY_STRING'] = requestant.query # name=john
Expand Down
38 changes: 38 additions & 0 deletions tests/core/http/falcon/test_falcon.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,44 @@ def on_get(self, req, rep):
exampleBackend = ExampleBackendEnd(tymth=tymist.tymen())
exapp.add_route('/example/backend', exampleBackend)

def test_get_request_with_utf8():
"""
Test a request with a utf-8 character
"""
tymist.tyme = 0.0 # reset for each test
with http.openServer(port=8101, bufsize=131072, app=exapp, \
tymth=tymist.tymen()) as server:

assert server.servant.ha == ('0.0.0.0', 8101)
assert server.servant.eha == ('127.0.0.1', 8101)

# request containing utf-8 character
path = "http://{}:{}{}".format('localhost',
server.servant.eha[1],
"/�")
headers = help.Hict([('Accept', 'application/json'),
('Content-Length', 0)])

with http.openClient(bufsize=131072, method='GET', path=path, \
headers=headers, reconnectable=True, \
tymth=tymist.tymen()) as client:

client.transmit()
while (client.requests or client.connector.txbs or not client.responses or
not server.idle()):
server.service()
time.sleep(0.05)
client.service()
time.sleep(0.05)
tymist.tick(tock=0.1)

assert len(client.responses) == 1
rep = client.responses.popleft()

# utf-8 character is not supported in the path
assert rep['status'] == 404

"""Done Test """


def test_get_backend():
Expand Down

0 comments on commit 0022d2b

Please sign in to comment.