Browse Source

Fix latin-1 handling in webhook header values

pull/551/head
Pēteris Caune 3 years ago
parent
commit
c196dc16d7
No known key found for this signature in database GPG Key ID: E28D7679E9A9EDE2
2 changed files with 19 additions and 1 deletions
  1. +18
    -0
      hc/api/tests/test_notify_webhook.py
  2. +1
    -1
      hc/api/transports.py

+ 18
- 0
hc/api/tests/test_notify_webhook.py View File

@ -359,3 +359,21 @@ class NotifyWebhookTestCase(BaseTestCase):
args, kwargs = mock_request.call_args
self.assertEqual(kwargs["headers"]["X-Foo"], "bār")
@patch("hc.api.transports.requests.request")
def test_webhooks_handle_latin1_in_headers(self, mock_request):
definition = {
"method_down": "GET",
"url_down": "http://foo.com",
"headers_down": {"X-Foo": "½"},
"body_down": "",
}
self._setup_data(json.dumps(definition))
self.check.save()
self.channel.notify(self.check)
args, kwargs = mock_request.call_args
self.assertEqual(kwargs["headers"]["X-Foo"], "½")

+ 1
- 1
hc/api/transports.py View File

@ -223,7 +223,7 @@ class Webhook(HttpTransport):
result = replace(template, ctx)
if latin1:
# Replace non-latin-1 characters with XML character references.
result = result.encode("latin-1", "xmlcharrefreplace").decode()
result = result.encode("latin-1", "xmlcharrefreplace").decode("latin-1")
return result


Loading…
Cancel
Save