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
Syntax error with ${{'foo':'bar'}} #20
Comments
Michael Bayer (@zzzeek) wrote: yeah unfortunately there will always be some issues like this one, it should be pretty obvious why this one is occurring (you know, its looking for a bracket). there is some logic to handle things like this which is already accounting for strings like ${"}") but thats because its counting quotes...i can look into it further but unless i rewrote the entire python parser there will always be things like this which can slip through (also, a typical MVC setup wouldnt really be declaring dictionaries inside of templates/expressions anyway, though thats not a 100% excuse.....) id like to see how other template languages handle phrases like that one. |
Changes by Michael Bayer (@zzzeek):
|
Anonymous wrote: I've simplfied the example for the demonstration, but following this example, this is not an excuse, not even 1%. :) From a Pylons point of view, I'd be tempted to do the following: ${h.link_to_remote("Home", options={"url":h.url_for("home"), "method":"get"})} How about extracting what's contained inside ${} as a string and do an eval() on the string ?
Just an idea... |
P C (@pc) wrote: Rather than fixing every such bug, may be a good idea to let user to increment number of braces if he needs. So that examples above writen as:
I consider this is better than escaping braces someway:
|
Anonymous wrote: Attached patch exploits |
Michael Bayer (@zzzeek) wrote: unfortunately, many tests fail with the latest patch. If the patch can be repaired such that all tests pass, we can put it in. Mako is due for a release so this one might have to wait for another go-around.... |
Anonymous wrote: Tavis has the following suggestion from Cheetah. -MO "I maintain a stack of enclosures (,[,{ to balance things out. See |
Michael Bayer (@zzzeek) wrote: yeah, i think an expansion of the current "quote counting" idea to just be a stack of enclosures is the most practical approach here. I had hopes for the "python compiler" approaches previously patched here but this would be more straightforward. |
Anonymous wrote: Werkzeug ships a minimal template engine for some small scripts and it solved that problem the same way Ka-Ping Yee's old interpolation code did with a small modification for newer Python versions: http://dev.pocoo.org/projects/werkzeug/browser/werkzeug/templates.py see |
Michael Bayer (@zzzeek) wrote: k, thats hopeful. i'm at energy level zero for mako these days so if someone wants to adapt that into a patch, that's a good path towards a fix. |
Anonymous wrote: I took a crack at this; it's not the most beautiful solution, but it should be correct. Fixes #86 as well. Added simple tests, all the tests pass, and the suite is even a whopping 4ms faster! Trac griped when I tried to attach a file, so patch here: https://gist.github.com/1713508 ~ @eevee |
Michael Bayer (@zzzeek) wrote: wow, that is really impressive ! as you can see, this bug has existed since day one and...ah someone else took a crack five years ago. I'll try running this across a huge pile of templates here and see what I get. |
Changes by Michael Bayer (@zzzeek):
|
Migrated issue, originally created by Anonymous
This works fine:
This crashes:
mako.exceptions.SyntaxException: (SyntaxError) unexpected EOF while parsing (line 1) ("{'method':'get'") in file [...]
Attachments: mako_braces.diff | mako_ticket20.diff | mako-lexer-fix.diff
The text was updated successfully, but these errors were encountered: