Closed
Description
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...
Reacted by Malthe Borch
Metadata
Metadata
Assignees
Labels
No labels
Activity
Update parser.py
Add files via upload
Update CHANGES.rst
wlang42 commentedon Apr 6, 2022
Pull request (including patch, tests, CHANGES): #351
wlang42 commentedon Apr 6, 2022
Aaaaahhhhhrrgg, i mistakenly uploaded the test files (
127-tags-and-attributes-special-chars.ptand127.pt) into the root folder:-(Should i make a new pull request to move those files into
tests/inputandtests/ouptut?icemac commentedon Apr 6, 2022
This seems to be the easiest way to fix it.
wlang42 commentedon Apr 6, 2022
Ok, will do...
move pt snippets into the right location (to be picked up by tests)
wlang42 commentedon Apr 6, 2022
Done: PR: #352
(Sorry for the mix up.)
malthe commentedon Apr 7, 2022
The fix for this is now released in 3.10.0.