aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWaylan Limberg <waylan@gmail.com>2012-12-13 14:05:33 -0500
committerWaylan Limberg <waylan@gmail.com>2012-12-13 14:05:33 -0500
commita8e06b7cef5c5b0b372b9a0db0f56c4e7094e2bd (patch)
tree9ecd110c42dedc349b12f0852bf6182025293c20
parente57b954a1f964ec0635d189c16d130c4e6ba5479 (diff)
downloadmarkdown-a8e06b7cef5c5b0b372b9a0db0f56c4e7094e2bd.tar.gz
markdown-a8e06b7cef5c5b0b372b9a0db0f56c4e7094e2bd.tar.bz2
markdown-a8e06b7cef5c5b0b372b9a0db0f56c4e7094e2bd.zip
Fixed #164. attr_list extension attribute names are now sanitized and won't crash the serealizer.
-rw-r--r--markdown/extensions/attr_list.py15
-rw-r--r--tests/extensions/attr_list.html3
-rw-r--r--tests/extensions/attr_list.txt1
3 files changed, 16 insertions, 3 deletions
diff --git a/markdown/extensions/attr_list.py b/markdown/extensions/attr_list.py
index 0aa18e0..36f3e3a 100644
--- a/markdown/extensions/attr_list.py
+++ b/markdown/extensions/attr_list.py
@@ -67,6 +67,10 @@ class AttrListTreeprocessor(markdown.treeprocessors.Treeprocessor):
HEADER_RE = re.compile(r'[ ]*%s[ ]*$' % BASE_RE)
BLOCK_RE = re.compile(r'\n[ ]*%s[ ]*$' % BASE_RE)
INLINE_RE = re.compile(r'^%s' % BASE_RE)
+ NAME_RE = re.compile(r'[^A-Z_a-z\xc0-\xd6\xd8-\xf6\u00f8-\u02ff\u0370-\u037d'
+ '\u037f-\u1fff\u200c-\u200d\u2070-\u218f\u2c00-\u2fef'
+ '\u3001-\ud7ff\uf900-\ufdcf\ufdf0-\ufffd\u10000-\ueffff'
+ '\-\.0-9\xb7\u0300-\u036f\u203f-\u2040]+')
def run(self, doc):
for elem in doc.getiterator():
@@ -114,8 +118,15 @@ class AttrListTreeprocessor(markdown.treeprocessors.Treeprocessor):
else:
elem.set('class', v)
else:
- # assing attr k with v
- elem.set(k, v)
+ # assign attr k with v
+ elem.set(self.sanitize_name(k), v)
+
+ def sanitize_name(self, name):
+ """
+ Sanitize name as 'an XML Name, minus the ":"'.
+ See http://www.w3.org/TR/REC-xml-names/#NT-NCName
+ """
+ return self.NAME_RE.sub('_', name)
class AttrListExtension(markdown.extensions.Extension):
diff --git a/tests/extensions/attr_list.html b/tests/extensions/attr_list.html
index 1e9c182..f50cd6a 100644
--- a/tests/extensions/attr_list.html
+++ b/tests/extensions/attr_list.html
@@ -14,4 +14,5 @@ And a <strong class="nest">nested <a class="linky2" href="http://example.com" ti
{: #someid .someclass }
</code></pre>
<h3 id="hash3">No colon for compatability with Headerid ext</h3>
-<p id="the_end">Also a codespan: <code class="foo">{: .someclass}</code>.</p> \ No newline at end of file
+<p id="the_end">Also a codespan: <code class="foo">{: .someclass}</code>.</p>
+<h3 _:="{:" id="hash5">Bad Syntax</h3> \ No newline at end of file
diff --git a/tests/extensions/attr_list.txt b/tests/extensions/attr_list.txt
index d7ed274..cd7f398 100644
--- a/tests/extensions/attr_list.txt
+++ b/tests/extensions/attr_list.txt
@@ -33,3 +33,4 @@ Now test overrides
Also a codespan: `{: .someclass}`{: .foo}.
{: #the_end}
+### Bad Syntax { {: #hash5 }