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

Parse error in chameleon template with python expression that contains nested curly braces #29

Closed
alveraan opened this Issue May 27, 2014 · 1 comment

Comments

Projects
None yet
2 participants
@alveraan

alveraan commented May 27, 2014

Using a python2.7 virtualenv with lingua 2.1 installed, I'm trying to do the following on a chameleon template:

$ $ENV/bin/pot-create -c lingua.cfg -d test test.pt

Where lingua.cfg contains:

[extension:.pt]
plugin = xml

[extension:.py]
plugin = python

and test.pt contains:

<html xmlns:i18n="http://xml.zope.org/namespaces/i18n"
  i18n:domain="test">
  <head><title>tetst</title></head>
  <body>
    <a href="${request.route_url('set_locale', _query={'somevar': 'somevalue'})}">Test</a>
  </body>
</html>

This fails with the following error:

Aborting due to parse error in ./test.pt[9]: request.route_url('set_locale', _query={'somevar': 'somevalue'

I think it has to do with the nested curly braces, because running the same command on

<html xmlns:i18n="http://xml.zope.org/namespaces/i18n"
  i18n:domain="test">
  <head><title>tetst</title></head>
  <body>
    <a href="${request.route_url('set_locale')}">Test</a>
  </body>
</html>

works without error.

@wichert

This comment has been minimized.

Show comment
Hide comment
@wichert

wichert May 27, 2014

Owner

Here is a failing testcase:

@pytest.mark.usefixtures('fake_source')
def test_curly_brace_in_python_attribute_expression():
    global source
    source = b'''\
            <html>
              <a href="${request.route_url('set_locale', _query={'locale': 'de'})}"></a>
            </html>
            '''
    list(extract_xml('filename', _options()))

The underlying problem is that the utility function to extract python expressions from an attribute value is somewhat naive and will stop at the first closing curly brace.

Owner

wichert commented May 27, 2014

Here is a failing testcase:

@pytest.mark.usefixtures('fake_source')
def test_curly_brace_in_python_attribute_expression():
    global source
    source = b'''\
            <html>
              <a href="${request.route_url('set_locale', _query={'locale': 'de'})}"></a>
            </html>
            '''
    list(extract_xml('filename', _options()))

The underlying problem is that the utility function to extract python expressions from an attribute value is somewhat naive and will stop at the first closing curly brace.

@wichert wichert closed this in bb8e9e2 May 27, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment