File tree Expand file tree Collapse file tree 4 files changed +30
-8
lines changed
example/unicorn/templates/unicorn Expand file tree Collapse file tree 4 files changed +30
-8
lines changed Original file line number Diff line number Diff line change @@ -81,10 +81,14 @@ def parse_args(args: str) -> List[Any]:
8181 """
8282 found_args = []
8383 arg = ""
84+
8485 curly_bracket_count = 0
8586 square_bracket_count = 0
8687 parenthesis_count = 0
8788
89+ in_single_quote = False
90+ in_double_quote = False
91+
8892 def _eval_arg (_arg ):
8993 try :
9094 _arg = literal_eval (_arg )
@@ -114,7 +118,7 @@ def _parse_arg(_arg):
114118 return _arg
115119
116120 for c in args :
117- if not c .strip ():
121+ if not in_single_quote and not in_double_quote and not c .strip ():
118122 continue
119123
120124 if (
@@ -147,6 +151,10 @@ def _parse_arg(_arg):
147151 elif c == ")" :
148152 parenthesis_count -= 1
149153 arg = _parse_arg (arg )
154+ elif c == "'" :
155+ in_single_quote = not in_single_quote
156+ elif c == '"' :
157+ in_double_quote = not in_double_quote
150158
151159 if arg :
152160 arg = _eval_arg (arg )
Original file line number Diff line number Diff line change 99
1010import orjson
1111
12- from .call_method_parser import (
13- InvalidKwarg ,
14- parse_args ,
15- parse_call_method_name ,
16- parse_kwarg ,
17- )
12+ from .call_method_parser import InvalidKwarg , parse_call_method_name , parse_kwarg
1813from .components import UnicornField , UnicornView
1914from .errors import UnicornViewError
2015from .utils import generate_checksum
Original file line number Diff line number Diff line change 3737 < button unicorn:click ="set_name "> set_name</ button >
3838 < button unicorn:click ="set_name() "> set_name()</ button >
3939 < button unicorn:click ="set_name('') "> set_name('')</ button >
40- < button unicorn:click ="set_name('blob') "> set_name('blob')</ button >
40+ < button unicorn:click ="set_name('blob 2 ') "> set_name('blob 2 ')</ button >
4141 < button unicorn:click ="name='human' "> name='human'</ button >
4242
4343 < br />
4444 Hello {{ name|title }} 👋
45+
46+ < br />
47+ < button unicorn:click ='set_name($event.target.value.trim()) ' value =' button value '> set_name($event.target.value.trim())</ button >
4548</ div >
Original file line number Diff line number Diff line change @@ -20,6 +20,22 @@ def test_single_quote_str_arg():
2020 assert isinstance (actual [0 ], str )
2121
2222
23+ def test_str_with_space_arg ():
24+ expected = ["django unicorn" ]
25+ actual = parse_args ("'django unicorn'" )
26+
27+ assert actual == expected
28+ assert isinstance (actual [0 ], str )
29+
30+
31+ def test_complicated_str_with_space_arg ():
32+ expected = ["django's \" ' unicorn" ]
33+ actual = parse_args ("django's \" ' unicorn" )
34+
35+ assert actual == expected
36+ assert isinstance (actual [0 ], str )
37+
38+
2339def test_double_quote_str_arg ():
2440 expected = ["1" ]
2541 actual = parse_args ('"1"' )
You can’t perform that action at this time.
0 commit comments