Permalink
Browse files

Merge pull request #4 from josephw/xhtml-div-checking

Check the namespace for divs in XHTML content.
  • Loading branch information...
2 parents 1300fdd + 36e53b3 commit 2f1e18b44d8834b858eb76633efdff3aac579fc2 @rubys committed Mar 17, 2013
Showing with 40 additions and 2 deletions.
  1. +9 −2 src/feedvalidator/content.py
  2. +31 −0 testcases/atom/3.1.1.3/wrong_namespace_for_xhtml_div.xml
@@ -5,6 +5,10 @@
from base import validatorBase, namespaces
from validators import *
from logging import *
+
+def _isXhtmlDiv(ns, elem):
+ return ns == 'http://www.w3.org/1999/xhtml' and elem == 'div'
+
#
# item element.
#
@@ -104,8 +108,11 @@ def startElementNS(self, name, qname, attrs):
self.log(UndefinedElement({"parent":self.name, "element":name}))
if self.type=="xhtml":
- if name<>'div' and not self.value.strip():
+ if not _isXhtmlDiv(qname, name) and not self.value.strip():
self.log(MissingXhtmlDiv({"parent":self.parent.name, "element":self.name}))
+ if name == 'div':
+ self.log(NotHtml({"parent":self.parent.name, "element":self.name, "message":"unexpected namespace", "value": qname}))
+
elif qname not in ["http://www.w3.org/1999/xhtml"]:
self.log(NotHtml({"parent":self.parent.name, "element":self.name, "message":"unexpected namespace", "value": qname}))
@@ -119,7 +126,7 @@ def startElementNS(self, name, qname, attrs):
if self.attrs.getValue((None,"mode")) == 'escaped':
self.log(NotEscaped({"parent":self.parent.name, "element":self.name}))
- if name=="div" and qname=="http://www.w3.org/1999/xhtml":
+ if _isXhtmlDiv(qname, name):
handler=diveater()
else:
handler=eater()
@@ -0,0 +1,31 @@
+<!--
+ Author: Sam Ruby (http://intertwingly.net/) and Mark Pilgrim (http://diveintomark.org/)
+ Copyright: Copyright (c) 2003 Sam Ruby and Mark Pilgrim
+-->
+
+<!--
+ Description: The div in xhtml content must be in the xhtml namespace
+ Expect: MissingXhtmlDiv{parent:entry,element:summary}
+-->
+
+<feed xmlns="http://www.w3.org/2005/Atom">
+
+ <title>Example Feed</title>
+ <link href="http://example.org/"/>
+ <updated>2003-12-13T18:30:02Z</updated>
+ <author>
+ <name>John Doe</name>
+ </author>
+ <id>urn:uuid:60a76c80-d399-11d9-b93C-0003939e0af6</id>
+
+ <entry>
+ <title>Atom-Powered Robots Run Amok</title>
+ <link href="http://example.org/2003/12/13/atom03"/>
+ <id>urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a</id>
+ <updated>2003-12-13T18:30:02Z</updated>
+ <summary type="xhtml" xmlns:xhtml="http://www.w3.org/1999/xhtml">
+ <div>This div isn't in the XHTML namespace.</div>
+ </summary>
+ </entry>
+
+</feed>

0 comments on commit 2f1e18b

Please sign in to comment.