Skip to content

Commit

Permalink
Fixed a bug where URLs are not being quoted correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
OwenCochell committed May 16, 2022
1 parent b3d5ad5 commit a5ab719
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 7 deletions.
2 changes: 1 addition & 1 deletion cursepy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@

# Define some metadata here:

__version__ = '1.3.0'
__version__ = '1.3.1'
__author__ = 'Owen Cochell'
14 changes: 9 additions & 5 deletions cursepy/proto.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@
import socket

from urllib.request import urlopen, Request
from urllib.parse import urlencode
from urllib.parse import urlencode, quote, urlsplit, urlunsplit
from http.client import HTTPResponse
from typing import Optional


class BaseProtocol(object):

"""
Base protocol implementation - All child protocols must inherit this class!
Expand Down Expand Up @@ -169,7 +168,6 @@ def write(self, byts: bytes):


class URLProtocol(BaseProtocol):

"""
URLProtocol - Gets information via HTTP.
Expand Down Expand Up @@ -327,6 +325,8 @@ def _request_build(self, url: str, data: Optional[dict]=None, heads: Optional[di
We point the request at the given url,
add content headers, and add the given data.
We also do necessary quoting on the url path,
so our urls are valid.
:param url: URL of the request
:type url: str
Expand All @@ -352,6 +352,10 @@ def _request_build(self, url: str, data: Optional[dict]=None, heads: Optional[di

heads = {}

# Make and return the request:
# Make and return the request, do some quoting on the path only:

split = urlsplit(url)

split = split._replace(path=quote(split.path))

return Request(url, data=encoded_data, headers={**self.headers, **heads})
return Request(urlunsplit(split), data=encoded_data, headers={**self.headers, **heads})
8 changes: 8 additions & 0 deletions docs/source/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@
Changelog
=========

1.3.1
=====

Bug Fixes
---------

* We now properly quote the path section of any URLs given to the URLProtocol

1.3.0
======

Expand Down
2 changes: 1 addition & 1 deletion docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
# -- Project information -----------------------------------------------------

project = 'cursepy'
copyright = '2021, Owen Cochell'
copyright = '2022, Owen Cochell'
author = 'Owen Cochell'

# The full version, including alpha/beta/rc tags
Expand Down

0 comments on commit a5ab719

Please sign in to comment.