From 3491955995009079dc34b19304378b6eb5763d9f Mon Sep 17 00:00:00 2001 From: Nikhil Rao Date: Mon, 6 Mar 2023 17:38:21 -0800 Subject: [PATCH] Fix format dict props (#641) --- pynecone/components/tags/tag.py | 1 + tests/components/test_tag.py | 11 ++++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/pynecone/components/tags/tag.py b/pynecone/components/tags/tag.py index fc076028a..e9c492cbe 100644 --- a/pynecone/components/tags/tag.py +++ b/pynecone/components/tags/tag.py @@ -108,6 +108,7 @@ class Tag(Base): # This substitution is necessary to unwrap var values. prop = re.sub('"{', "", prop) prop = re.sub('}"', "", prop) + prop = re.sub('\\\\"', '"', prop) # Wrap the variable in braces. assert isinstance(prop, str), "The prop must be a string." diff --git a/tests/components/test_tag.py b/tests/components/test_tag.py index 349a4fceb..d9029df85 100644 --- a/tests/components/test_tag.py +++ b/tests/components/test_tag.py @@ -39,9 +39,18 @@ def mock_event(arg): ), '{(e) => Event([E("mock_event", {arg:e.target.value})])}', ), + ({"a": "red", "b": "blue"}, '{{"a": "red", "b": "blue"}}'), + (BaseVar(name="var", type_="int"), "{var}"), + (BaseVar(name='state.colors["a"]', type_="str"), '{state.colors["a"]}'), + ({"a": BaseVar(name="val", type_="str")}, '{{"a": val}}'), + ({"a": BaseVar(name='"val"', type_="str")}, '{{"a": "val"}}'), + ( + {"a": BaseVar(name='state.colors["val"]', type_="str")}, + '{{"a": state.colors["val"]}}', + ), ], ) -def test_format_value(prop: Var, formatted: str): +def test_format_prop(prop: Var, formatted: str): """Test that the formatted value of an prop is correct. Args: