forked from GithubBackups/healthchecks
Fix latin-1 handling in webhook header values
This commit is contained in:
parent
b43612806f
commit
c196dc16d7
@ -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"], "½")
|
||||
|
||||
|
@ -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…
x
Reference in New Issue
Block a user