Skip to content

Commit

Permalink
Throw error if double hyphen appears in XML comment
Browse files Browse the repository at this point in the history
This closes issue 216.
  • Loading branch information
malthe committed Dec 5, 2016
1 parent 8eb4be7 commit f2cad59
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CHANGES.rst
Expand Up @@ -3,6 +3,9 @@ Changes

In next release ...

- Throw a parse error if '--' (double hyphen) appears in an XML
comment.

- Add support for non-ascii attribute names.
[sank]

Expand Down
7 changes: 7 additions & 0 deletions src/chameleon/parser.py
Expand Up @@ -10,6 +10,7 @@
from .namespaces import XML_NS
from .tokenize import Token

match_double_hyphen = re.compile(r'--(?!>)')
match_tag_prefix_and_name = re.compile(
r'^(?P<prefix></?)(?P<name>([^:\n\r ]+:)?[^ \n\t\r>/]+)'
'(?P<suffix>(?P<space>\s*)/?>)?',
Expand Down Expand Up @@ -152,6 +153,12 @@ def unpack_attributes(attributes, namespace, default):
def identify(string):
if string.startswith("<"):
if string.startswith("<!--"):
m = match_double_hyphen.search(string[4:])
if m is not None:
raise ParseError(
"The string '--' is not allowed in a comment.",
string[4 + m.start():4 + m.end()]
)
return "comment"
if string.startswith("<![CDATA["):
return "cdata"
Expand Down

0 comments on commit f2cad59

Please sign in to comment.