Skip to content

Commit 9e7dc96

Browse files
author
Mark Pilgrim
committed
added support for validating <base target> attribute
--HG-- extra : convert_revision : svn%3Aacbfec75-9323-0410-a652-858a13e371e0/trunk%40986
1 parent d11eff2 commit 9e7dc96

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

src/html5lib/filters/validator.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@
6262
_(u"Value must be an integer: '%(attributeName)s' attribute on <%tagName)s>."),
6363
"invalid-root-namespace":
6464
_(u"Root namespace must be 'http://www.w3.org/1999/xhtml', or omitted."),
65+
"invalid-browsing-context":
66+
_(u"Value must be one of ('_self', '_parent', '_top'), or a name that does not start with '_': '%(attributeName)s' attribute on <%(tagName)s>."),
6567
})
6668

6769
globalAttributes = frozenset(('class', 'contenteditable', 'contextmenu', 'dir',
@@ -402,13 +404,28 @@ def validateAttributeValueId(self, token, tagName, attrName, attrValue):
402404
def validateAttributeValueTabindex(self, token, tagName, attrName, attrValue):
403405
for t in self.checkIntegerValue(token, tagName, attrName, attrValue) or []: yield t
404406

407+
def validateAttributeValueRef(self, token, tagName, attrName, attrValue):
408+
# XXX
409+
pass
410+
411+
def validateAttributeValueTemplate(self, token, tagName, attrName, attrValue):
412+
# XXX
413+
pass
414+
405415
def validateAttributeValueHtmlXmlns(self, token, tagName, attrName, attrValue):
406416
if attrValue != "http://www.w3.org/1999/xhtml":
407417
yield {"type": "ParseError",
408418
"data": "invalid-root-namespace",
409419
"datavars": {"tagName": tagName,
410420
"attributeName": attrName}}
411421

422+
def validateAttributeValueBaseHref(self, token, tagName, attrName, attrValue):
423+
# XXX
424+
pass
425+
426+
def validateAttributeValueBaseTarget(self, token, tagName, attrName, attrValue):
427+
for t in self.checkBrowsingContext(token, tagName, attrName, attrValue) or []: yield t
428+
412429
##########################################################################
413430
# Attribute validation helpers
414431
##########################################################################
@@ -525,6 +542,16 @@ def checkIntegerValue(self, token, tagName, attrName, attrValue):
525542
"datavars": {"tagName": tagName,
526543
"attributeName": attrName}}
527544

545+
def checkBrowsingContext(self, token, tagName, attrName, attrValue):
546+
if not attrValue: return
547+
if attrValue[0] != '_': return
548+
attrValue = attrValue.lower()
549+
if attrValue in frozenset(('_self', '_parent', '_top', '_blank')): return
550+
yield {"type": "ParseError",
551+
"data": "invalid-browsing-context",
552+
"datavars": {"tagName": tagName,
553+
"attributeName": attrName}}
554+
528555
##########################################################################
529556
# Whole document validation (IDs, etc.)
530557
##########################################################################

0 commit comments

Comments
 (0)