ext/html: Mixins are broken when passing single argument
Here is a minimal example:
mixin test(arg)
p= arg
.hello
+test('world')
Expected result:
<div class="hello">
<p>world</p>
</div>
Actual result:
<div class="hello">
<p>w</p>
</div>
While does it happen: in ext.html.Compiler._make_mixin._mixin, arguments are parsed like this:
if args:
arg_values = self._do_eval(args)
else:
arg_values = []
...
local_context = dict(zip(arg_names, arg_values))
As a result, if there are at least 2 arguments passed, args is something like 'world', 2 and is evaluated to tuple: ('world', 2). Then later zip properly joins sequence of names with sequence of values.
But if there is only one argument, then eval returns this argument. As a result, string is interpreted as a sequence of characters. And if it is not a string but something more complex (like WTForms field) then we get error.
How can this be fixed:
I think that before passing args to _do_eval we should just wrap them with []:
arg_values = self._do_eval('[%s]' % (args or ''))
This will properly work even when no arguments was passed.
And for now there is a workaround: add , after last argument.