Skip to content

Commit

Permalink
Unescape text sent to Textlab API
Browse files Browse the repository at this point in the history
  • Loading branch information
timobrembeck committed Oct 26, 2022
1 parent 20f6659 commit 06f0d2b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
UNRELEASED
----------

* [ [#1808](https://github.com/digitalfabrik/integreat-cms/issues/1808) ] Unescape HTML characters sent to Textlab API
* [ [#1800](https://github.com/digitalfabrik/integreat-cms/issues/1800) ] Exclude archived pages from PDF exports
* [ [#1802](https://github.com/digitalfabrik/integreat-cms/issues/1802) ] Reenable table of contents and page numbers in PDFs
* [ [#1350](https://github.com/digitalfabrik/integreat-cms/issues/1350) ] Various small PDF export improvements
Expand Down
8 changes: 6 additions & 2 deletions integreat_cms/textlab_api/textlab_api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
from urllib.error import HTTPError
from urllib.request import Request, urlopen

from html import unescape

from django.conf import settings
from django.core.exceptions import ImproperlyConfigured

Expand Down Expand Up @@ -48,7 +50,7 @@ def benchmark(self, text):
:raises urllib.error.HTTPError: if an http error occurred
"""
data = {"text": text, "locale_name": "de_DE"}
data = {"text": unescape(text), "locale_name": "de_DE"}
path = "/benchmark/5"
try:
response = self.post_request(path, data, self.token)
Expand Down Expand Up @@ -76,7 +78,9 @@ def post_request(path, data, auth_token=None):
:raises urllib.error.HTTPError: If the request failed
"""
data = json.dumps(data).encode("utf-8")
request = Request(f"{settings.TEXTLAB_API_URL}{path}", data=data, method="POST")
request = Request(
f"{settings.TEXTLAB_API_URL.rstrip('/')}{path}", data=data, method="POST"
)
if auth_token:
request.add_header("authorization", f"Bearer {auth_token}")
request.add_header("Content-Type", "application/json")
Expand Down

0 comments on commit 06f0d2b

Please sign in to comment.