Skip to content

Tag not Parseable with Tab and Colon #350

Closed

Description

@wlang42

If a PageTemplate tag is separated with a tab from a following attribute and
that attribute name contains a colon, the tag is not parsed correctly. It can be
reproduced with Chameleon-3.9.0 and the following sample script:

import chameleon
src = """\
<tal:block>
  <div\tstyle="height:97px">
  </div>
</tal:block>
"""
pt = chameleon.PageTemplate(src)

Running it with python2.7 gives:

Traceback (most recent call last):
  File "pttest.py", line 10, in <module>
    pt = chameleon.PageTemplate(src)
  File "/usr/local/lib/python2.7/site-packages/Chameleon-3.9.0-py2.7.egg/chameleon/zpt/template.py", line 205, in __init__
    super(PageTemplate, self).__init__(body, **config)
  File "/usr/local/lib/python2.7/site-packages/Chameleon-3.9.0-py2.7.egg/chameleon/template.py", line 137, in __init__
    self.write(body)
  File "/usr/local/lib/python2.7/site-packages/Chameleon-3.9.0-py2.7.egg/chameleon/template.py", line 232, in write
    self.cook(body)
  File "/usr/local/lib/python2.7/site-packages/Chameleon-3.9.0-py2.7.egg/chameleon/template.py", line 167, in cook
    program = self._cook(body, digest, names)
  File "/usr/local/lib/python2.7/site-packages/Chameleon-3.9.0-py2.7.egg/chameleon/template.py", line 242, in _cook
    source = self._compile(body, builtins)
  File "/usr/local/lib/python2.7/site-packages/Chameleon-3.9.0-py2.7.egg/chameleon/template.py", line 274, in _compile
    program = self.parse(body)
  File "/usr/local/lib/python2.7/site-packages/Chameleon-3.9.0-py2.7.egg/chameleon/zpt/template.py", line 238, in parse
    tokenizer=self.tokenizer
  File "/usr/local/lib/python2.7/site-packages/Chameleon-3.9.0-py2.7.egg/chameleon/zpt/program.py", line 174, in __init__
    super(MacroProgram, self).__init__(*args, **kwargs)
  File "/usr/local/lib/python2.7/site-packages/Chameleon-3.9.0-py2.7.egg/chameleon/program.py", line 34, in __init__
    for kind, args in parser:
  File "/usr/local/lib/python2.7/site-packages/Chameleon-3.9.0-py2.7.egg/chameleon/parser.py", line 196, in __iter__
    item = self.parse(token)
  File "/usr/local/lib/python2.7/site-packages/Chameleon-3.9.0-py2.7.egg/chameleon/parser.py", line 204, in parse
    return visitor(kind, token)
  File "/usr/local/lib/python2.7/site-packages/Chameleon-3.9.0-py2.7.egg/chameleon/parser.py", line 248, in visit_end_tag
    raise ParseError("Unexpected end tag.", token)
chameleon.exc.ParseError: Unexpected end tag.

 - String:     "</div>"
 - Filename:   <string>
 - Location:   (line 3: col 2)
 - Source:     </div>
               ^^^^^^

The reason is, that chameleon.parser.match_tag_prefix_and_name
parses the tag name as div\tstyle="height:97px". Then clearly the
closing tag </div> does not match.

This can easily be fixed:

bach-s97:~/github/Chameleon$ svn diff
Index: src/chameleon/parser.py
===================================================================
--- src/chameleon/parser.py     (revision 1121)
+++ src/chameleon/parser.py     (working copy)
@@ -12,7 +12,7 @@
 
 match_double_hyphen = re.compile(r'--(?!(-)*>)')
 match_tag_prefix_and_name = re.compile(
-    r'^(?P<prefix></?)(?P<name>([^:\n\r ]+:)?[^ \n\t\r>/]+)'
+    r'^(?P<prefix></?)(?P<name>([^:\n\t\r ]+:)?[^ \n\t\r>/]+)'
     r'(?P<suffix>(?P<space>\s*)/?>)?',
     re.UNICODE | re.DOTALL)
 match_single_attribute = re.compile(

(it is related to commit 9006d17)

I will try to make a pull request...

Activity

  1. wlang42 commented on Apr 6, 2022

    @wlang42
    ContributorAuthor

    Pull request (including patch, tests, CHANGES): #351

  2. wlang42 commented on Apr 6, 2022

    @wlang42
    ContributorAuthor

    Aaaaahhhhhrrgg, i mistakenly uploaded the test files (127-tags-and-attributes-special-chars.pt and 127.pt) into the root folder:-(

    Should i make a new pull request to move those files into tests/input and tests/ouptut?

  3. icemac commented on Apr 6, 2022

    @icemac
    Contributor

    Should i make a new pull request to move those files into tests/input and tests/ouptut?

    This seems to be the easiest way to fix it.

  4. wlang42 commented on Apr 6, 2022

    @wlang42
    ContributorAuthor

    Ok, will do...

  5. wlang42 commented on Apr 6, 2022

    @wlang42
    ContributorAuthor

    Done: PR: #352
    (Sorry for the mix up.)

  6. malthe commented on Apr 7, 2022

    @malthe
    Owner

    The fix for this is now released in 3.10.0.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions