Skip to content

Commit

Permalink
Fix format dict props (#641)
Browse files Browse the repository at this point in the history
  • Loading branch information
picklelo committed Mar 7, 2023
1 parent d74efb9 commit 3491955
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
1 change: 1 addition & 0 deletions pynecone/components/tags/tag.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ def format_prop(
# 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."
Expand Down
11 changes: 10 additions & 1 deletion tests/components/test_tag.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 3491955

Please sign in to comment.