diff --git a/CHANGELOG.md b/CHANGELOG.md index e5dc7f92..34043d00 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## Unreleased +### Fixed + +- Fix unicode characters not rendering correctly in webhooks @mderynck ([#3670](https://github.com/grafana/oncall/pull/3670)) + ## v1.3.84 (2024-01-10) ### Added diff --git a/engine/apps/webhooks/tests/test_webhook.py b/engine/apps/webhooks/tests/test_webhook.py index a86dd3b2..a0be802a 100644 --- a/engine/apps/webhooks/tests/test_webhook.py +++ b/engine/apps/webhooks/tests/test_webhook.py @@ -278,3 +278,21 @@ def test_escaping_payload_with_single_quote_in_string(make_organization, make_cu } request_kwargs = webhook.build_request_kwargs(payload) assert request_kwargs == {"headers": {}, "json": {"data": "{'text': \"Hi, it's alert\"}"}} + + +@pytest.mark.django_db +def test_escaping_unicode_in_string(make_organization, make_custom_webhook): + organization = make_organization() + webhook = make_custom_webhook( + organization=organization, + data='{"data" : "{{ alert_payload.text }}"}', + forward_all=False, + ) + + payload = { + "alert_payload": { + "text": "東京", + } + } + request_kwargs = webhook.build_request_kwargs(payload) + assert request_kwargs == {"headers": {}, "json": {"data": "東京"}} diff --git a/engine/apps/webhooks/utils.py b/engine/apps/webhooks/utils.py index 8599dd45..a7099559 100644 --- a/engine/apps/webhooks/utils.py +++ b/engine/apps/webhooks/utils.py @@ -82,7 +82,7 @@ def escape_string(string: str): json.dumps is the simples way to escape all special characters in string. First and last chars are quotes from json.dumps(), we don't need them, only escaping. """ - return json.dumps(string)[1:-1] + return json.dumps(string, ensure_ascii=False)[1:-1] class EscapeDoubleQuotesDict(dict):