From 68454cdd826d60b9eb55ac41e5bef3feccd0dd56 Mon Sep 17 00:00:00 2001 From: Arijit Basu Date: Wed, 21 Feb 2024 19:23:24 +0530 Subject: [PATCH 1/5] Pass by value --- tests/data/html/xss.html | 2 +- tiptapy/__init__.py | 18 +++++++----------- 2 files changed, 8 insertions(+), 12 deletions(-) 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/tiptapy/__init__.py b/tiptapy/__init__.py index c3face7..d7e411d 100644 --- a/tiptapy/__init__.py +++ b/tiptapy/__init__.py @@ -50,18 +50,14 @@ 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) + new = { + escape(k): v if k == skip_key else escape_values_recursive(v) + for k, v in node.items() + } + return new 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] + return new elif isinstance(node, str): return escape(node) return node From 9f5203df3e795c113b20ee5bf0b2c53629cc17d1 Mon Sep 17 00:00:00 2001 From: Arijit Basu Date: Wed, 21 Feb 2024 19:25:38 +0530 Subject: [PATCH 2/5] Update version --- CHANGELOG.rst | 4 ++++ setup.cfg | 2 +- setup.py | 2 +- tiptapy/__init__.py | 2 +- 4 files changed, 7 insertions(+), 3 deletions(-) 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/tiptapy/__init__.py b/tiptapy/__init__.py index d7e411d..3da1560 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 = {} From 28f51a90a2a76996ffd7bbc3dc3ba23d476db8a3 Mon Sep 17 00:00:00 2001 From: Arijit Basu Date: Wed, 21 Feb 2024 19:28:53 +0530 Subject: [PATCH 3/5] Minor --- tiptapy/__init__.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tiptapy/__init__.py b/tiptapy/__init__.py index 3da1560..252ff08 100644 --- a/tiptapy/__init__.py +++ b/tiptapy/__init__.py @@ -57,7 +57,6 @@ def escape_values_recursive(node): return new elif isinstance(node, list): return [escape_values_recursive(x) for x in node] - return new elif isinstance(node, str): return escape(node) return node From 38f7a34947b4df81fe7fcb6f0fd3b2e64ab81415 Mon Sep 17 00:00:00 2001 From: Arijit Basu Date: Wed, 21 Feb 2024 19:29:30 +0530 Subject: [PATCH 4/5] Cleanup --- tiptapy/__init__.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tiptapy/__init__.py b/tiptapy/__init__.py index 252ff08..5c75434 100644 --- a/tiptapy/__init__.py +++ b/tiptapy/__init__.py @@ -50,11 +50,10 @@ def escape_values_recursive(node): skip_key = "html" if isinstance(node, dict): - new = { + return { escape(k): v if k == skip_key else escape_values_recursive(v) for k, v in node.items() } - return new elif isinstance(node, list): return [escape_values_recursive(x) for x in node] elif isinstance(node, str): From 8e7c25bb90b285e2b21434c76549c6a20e0cfff5 Mon Sep 17 00:00:00 2001 From: Arijit Basu Date: Wed, 21 Feb 2024 19:32:55 +0530 Subject: [PATCH 5/5] Test --- tests/test_transform.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) 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