Skip to content

Commit

Permalink
Merge pull request #24 from docentYT/development
Browse files Browse the repository at this point in the history
v2.1.1
  • Loading branch information
docentYT authored Jan 29, 2024
2 parents 167208b + a3107be commit 41dc557
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [2.1.1]
### Fixed
- Percent-encoding was not applied on texts entered by the user. [#22](https://github.com/docentYT/osm_easy_api/issues/22)

## [2.1.0]
### Added
- `TooManyRequests` exception.
Expand Down
2 changes: 2 additions & 0 deletions src/osm_easy_api/api/_URLs.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# REMEMBER TO ADD urllib.parse.quote WHEN FORMATTING TEXT PROVIDED BY USER!!!

from typing import Dict

class URLs:
Expand Down
4 changes: 3 additions & 1 deletion src/osm_easy_api/api/endpoints/changeset_discussion.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

from ...api import exceptions

import urllib.parse

class Changeset_Discussion_Container:
def __init__(self, outer):
self.outer: "Api" = outer
Expand All @@ -18,7 +20,7 @@ def comment(self, changeset_id: int, text: str) -> None:
Raises:
exceptions.ChangesetNotClosed: Changeset must be closed to add comment.
"""
response = self.outer._request(self.outer._RequestMethods.POST, self.outer._url.changeset_discussion["comment"].format(id=changeset_id, text=text), self.outer._Requirement.YES, auto_status_code_handling=False)
response = self.outer._request(self.outer._RequestMethods.POST, self.outer._url.changeset_discussion["comment"].format(id=changeset_id, text=urllib.parse.quote(text)), self.outer._Requirement.YES, auto_status_code_handling=False)

match response.status_code:
case 200: pass
Expand Down
7 changes: 4 additions & 3 deletions src/osm_easy_api/api/endpoints/notes.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from ...data_classes import User, Note, Comment

from copy import deepcopy
import urllib.parse
from xml.etree import ElementTree

class Notes_Container:
Expand Down Expand Up @@ -131,7 +132,7 @@ def create(self, latitude: str, longitude: str, text: str) -> Note:
Note: Object of newly created note.
"""
generator = self.outer._post_generator(
url=self.outer._url.note["create"].format(latitude=latitude, longitude=longitude, text=text),
url=self.outer._url.note["create"].format(latitude=latitude, longitude=longitude, text=urllib.parse.quote(text)),
auth_requirement=self.outer._Requirement.OPTIONAL,
auto_status_code_handling=True)

Expand All @@ -152,7 +153,7 @@ def comment(self, id: int, text: str) -> Note:
Note: Note object of commented note
"""
status_code, generator = self.outer._post_generator(
url=self.outer._url.note["comment"].format(id=id, text=text),
url=self.outer._url.note["comment"].format(id=id, text=urllib.parse.quote(text)),
auth_requirement=self.outer._Requirement.YES,
auto_status_code_handling=False)

Expand Down Expand Up @@ -274,7 +275,7 @@ def search(self, text: str, limit: int = 100, closed_days: int = 7, user_id: int
Returns:
list[Note]: List of notes objects.
"""
url=self.outer._url.note["search"].format(text=text, limit=limit, closed=closed_days)
url=self.outer._url.note["search"].format(text=urllib.parse.quote(text), limit=limit, closed=closed_days)
if user_id: url += f"&user={user_id}"
if from_date: url += f"&from={from_date}"
if to_date: url += f"&from={to_date}"
Expand Down

0 comments on commit 41dc557

Please sign in to comment.