From 357962401b2001ab2f140516a55382c723dc9f66 Mon Sep 17 00:00:00 2001 From: docentYT <63965954+docentYT@users.noreply.github.com> Date: Wed, 6 Sep 2023 18:08:14 +0200 Subject: [PATCH 1/3] Update CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index eb27028..6f31a6b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,7 @@ 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.0] -#### Added +### Added - `TooManyRequests` exception. - Support for `429` status code in `api.changeset.discussion.comment()`. From 2f0c497090553d351dacb4ef4ee98aa7afae5eb9 Mon Sep 17 00:00:00 2001 From: docentYT <63965954+docentYT@users.noreply.github.com> Date: Mon, 29 Jan 2024 16:58:24 +0100 Subject: [PATCH 2/3] fix #22 --- CHANGELOG.md | 4 ++++ src/osm_easy_api/api/_URLs.py | 2 ++ src/osm_easy_api/api/endpoints/changeset_discussion.py | 4 +++- src/osm_easy_api/api/endpoints/notes.py | 7 ++++--- 4 files changed, 13 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6f31a6b..5c95119 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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). +## [Unreleased] +### 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. diff --git a/src/osm_easy_api/api/_URLs.py b/src/osm_easy_api/api/_URLs.py index c85d483..cbfa34a 100644 --- a/src/osm_easy_api/api/_URLs.py +++ b/src/osm_easy_api/api/_URLs.py @@ -1,3 +1,5 @@ +# REMEMBER TO ADD urllib.parse.quote WHEN FORMATTING TEXT PROVIDED BY USER!!! + from typing import Dict class URLs: diff --git a/src/osm_easy_api/api/endpoints/changeset_discussion.py b/src/osm_easy_api/api/endpoints/changeset_discussion.py index 6ec451d..c549e42 100644 --- a/src/osm_easy_api/api/endpoints/changeset_discussion.py +++ b/src/osm_easy_api/api/endpoints/changeset_discussion.py @@ -4,6 +4,8 @@ from ...api import exceptions +import urllib.parse + class Changeset_Discussion_Container: def __init__(self, outer): self.outer: "Api" = outer @@ -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 diff --git a/src/osm_easy_api/api/endpoints/notes.py b/src/osm_easy_api/api/endpoints/notes.py index 3553879..b9305cf 100644 --- a/src/osm_easy_api/api/endpoints/notes.py +++ b/src/osm_easy_api/api/endpoints/notes.py @@ -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: @@ -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) @@ -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) @@ -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}" From a3107be1df0dbea2f0a40389135a4baae072e6e7 Mon Sep 17 00:00:00 2001 From: docentYT <63965954+docentYT@users.noreply.github.com> Date: Mon, 29 Jan 2024 20:27:19 +0100 Subject: [PATCH 3/3] v2.1.1 --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5c95119..a4bf7c4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,7 @@ 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). -## [Unreleased] +## [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)