Coffee-fueled-deadlines / OSRSBytes

OSRSBytes is an all-in-one Python library for Old School Runescape (OSRS) that features Item Information Lookup, OSRS Hiscores, and Grand Exchange Market information.
Eclipse Public License 2.0
49 stars 13 forks source link

bug: Spaces in a name are unsupported #8

Closed SaffatHasan closed 3 years ago

SaffatHasan commented 3 years ago

Expected Behavior The consumer is attempting to access a user with a space in their name

from OSRSBytes import Hiscores
userName = 'Lynx Titan'
user = Hiscores(userName)

The consumer should receive the User object associated with that username's high scores.

Actual Behavior The library does not sanitize the username and directly passes in Lynx Titan (with a space) which results in an invalid URL.

Possible Solutions

  1. self.username.replace(' ', '%A0')
  2. Use a library to sanitize HTTP url

Stack Trace

    user = Hiscores(userName)
..\..\appdata\local\programs\python\python38-32\lib\site-packages\OSRSBytes\Hiscores.py:106: in __init__
    self._getHTTPResponse()
..\..\appdata\local\programs\python\python38-32\lib\site-packages\OSRSBytes\Hiscores.py:196: in _getHTTPResponse
    conn.request("GET", "/m=hiscore_oldschool/index_lite.ws?player={}".format(self.username))
..\..\appdata\local\programs\python\python38-32\lib\http\client.py:1230: in request
    self._send_request(method, url, body, headers, encode_chunked)
..\..\appdata\local\programs\python\python38-32\lib\http\client.py:1241: in _send_request
    self.putrequest(method, url, **skips)
..\..\appdata\local\programs\python\python38-32\lib\http\client.py:1092: in putrequest
    self._validate_path(url)
Coffee-fueled-deadlines commented 3 years ago

Fixed by TylerSweat (https://github.com/Coffee-fueled-deadlines/OSRSBytes/commit/20e37b5e68534fb5714d4c8b1ff271c1dc374749)