Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ext/html: Mixins are broken when passing single argument #249

Open
MarSoft opened this issue Apr 17, 2016 · 1 comment
Open

ext/html: Mixins are broken when passing single argument #249

MarSoft opened this issue Apr 17, 2016 · 1 comment

Comments

@MarSoft
Copy link

MarSoft commented Apr 17, 2016

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.

@MarSoft
Copy link
Author

MarSoft commented Apr 17, 2016

And for now there is a workaround: add , after last argument.

@MarSoft MarSoft closed this as completed Apr 17, 2016
@MarSoft MarSoft reopened this Apr 17, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant