diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 3ae22ab..8a33b6d 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -2,6 +2,10 @@ History ======= +0.18.1 (2024-02-21) +------------------- +- Fixed blocks data getting updated due to pass by reference + 0.18.0 (2024-02-09) ------------------- - html.escape all the attributes diff --git a/setup.cfg b/setup.cfg index e682e80..9dab429 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,5 +1,5 @@ [bumpversion] -current_version = 0.18.0 +current_version = 0.18.1 commit = True tag = True diff --git a/setup.py b/setup.py index 1b9efb3..8fd2176 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ setup( name="tiptapy", - version="0.18.0", # TODO: why bumpversion works only for single quotes? + version="0.18.1", # TODO: why bumpversion works only for single quotes? url="https://github.com/scrolltech/tiptapy", description="Library that generates HTML output from JSON export of tiptap editor", long_description=open("README.md").read(), diff --git a/tests/data/html/xss.html b/tests/data/html/xss.html index cbbad2a..1cb7c0e 100644 --- a/tests/data/html/xss.html +++ b/tests/data/html/xss.html @@ -1 +1 @@ -

<script>alert('pwned!');</script>

\ No newline at end of file +

<script>alert('pwned!');</script>

\ No newline at end of file diff --git a/tests/test_transform.py b/tests/test_transform.py index be02a58..1decf32 100644 --- a/tests/test_transform.py +++ b/tests/test_transform.py @@ -1,4 +1,5 @@ import os +from copy import deepcopy import pytest @@ -87,7 +88,11 @@ def test_html_tag(tag): Test expected json input with the expected html. """ tag_data = json_data[tag] - expected_html = html_data[tag] + tag_data_copy = deepcopy(tag_data) + expected_html = html_data[tag].strip() renderer = tiptapy.BaseDoc(config) - assert renderer.render(tag_data) == expected_html.strip() + rendered_html = renderer.render(tag_data).strip() + + assert rendered_html == expected_html + assert tag_data == tag_data_copy # Test pass by value diff --git a/tiptapy/__init__.py b/tiptapy/__init__.py index c3face7..5c75434 100644 --- a/tiptapy/__init__.py +++ b/tiptapy/__init__.py @@ -14,7 +14,7 @@ make_img_src, ) -__version__ = "0.18.0" +__version__ = "0.18.1" renderers: Dict = {} @@ -50,18 +50,12 @@ def escape_values_recursive(node): skip_key = "html" if isinstance(node, dict): - items = list(node.items()) - for k, v in items: - esc_k = escape(k) - if k != esc_k: - del node[k] - if esc_k == skip_key: - node[esc_k] = v - else: - node[esc_k] = escape_values_recursive(v) + return { + escape(k): v if k == skip_key else escape_values_recursive(v) + for k, v in node.items() + } elif isinstance(node, list): - for i, v in enumerate(node): - node[i] = escape_values_recursive(v) + return [escape_values_recursive(x) for x in node] elif isinstance(node, str): return escape(node) return node