From ffad5cca9779f54534ce32f094c46eb588a648a4 Mon Sep 17 00:00:00 2001 From: dgtlmoon Date: Sun, 13 Mar 2022 11:37:51 +0100 Subject: [PATCH] JSON diff/preview should use utf-8 encoding where possible (#465) --- changedetectionio/html_tools.py | 3 ++- changedetectionio/tests/test_jsonpath_selector.py | 7 +++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/changedetectionio/html_tools.py b/changedetectionio/html_tools.py index dc7c846c..fda2cf25 100644 --- a/changedetectionio/html_tools.py +++ b/changedetectionio/html_tools.py @@ -78,7 +78,8 @@ def _parse_json(json_data, jsonpath_filter): # Re 265 - Just return an empty string when filter not found return '' - stripped_text_from_html = json.dumps(s, indent=4) + # Ticket #462 - allow the original encoding through, usually it's UTF-8 or similar + stripped_text_from_html = json.dumps(s, indent=4, ensure_ascii=False) return stripped_text_from_html diff --git a/changedetectionio/tests/test_jsonpath_selector.py b/changedetectionio/tests/test_jsonpath_selector.py index a5329b67..dbe4725d 100644 --- a/changedetectionio/tests/test_jsonpath_selector.py +++ b/changedetectionio/tests/test_jsonpath_selector.py @@ -1,4 +1,5 @@ #!/usr/bin/python3 +# coding=utf-8 import time from flask import url_for @@ -142,7 +143,7 @@ def set_modified_response(): } ], "boss": { - "name": "Foobar" + "name": "Örnsköldsvik" }, "available": false } @@ -246,8 +247,10 @@ def test_check_json_filter(client, live_server): # Should not see this, because its not in the JSONPath we entered res = client.get(url_for("diff_history_page", uuid="first")) + # But the change should be there, tho its hard to test the change was detected because it will show old and new versions - assert b'Foobar' in res.data + # And #462 - check we see the proper utf-8 string there + assert "Örnsköldsvik".encode('utf-8') in res.data def test_check_json_filter_bool_val(client, live_server):