Skip to content

Commit 10f627a

Browse files
author
Mark Pilgrim
committed
added support for validating dir attribute
--HG-- extra : convert_revision : svn%3Aacbfec75-9323-0410-a652-858a13e371e0/trunk%40979
1 parent 32227cb commit 10f627a

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

src/html5lib/filters/validator.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@
4949
_(u"This value can not be blank: '%(attributeName)s' attribute on <%(tagName)s>."),
5050
"id-does-not-exist":
5151
_(u"This value refers to a non-existent ID: '%(attributeName)s' attribute on <%(tagName)s>."),
52+
"invalid-enumerated-value":
53+
_(u"Value must be one of %(enumeratedValues)s: '%(attributeName)s' attribute on <%tagName)s>."),
5254
"contextmenu-must-point-to-menu":
5355
_(u"The contextmenu attribute must point to an ID defined on a <menu> element."),
5456
})
@@ -358,8 +360,25 @@ def validateAttributeValueClass(self, token, tagName, attrName, attrValue):
358360
"attributeName": attrName}}
359361

360362
def validateAttributeValueContenteditable(self, token, tagName, attrName, attrValue):
363+
for t in self.checkEnumeratedValue(token, tagName, attrName, attrValue, frozenset(('true', 'false', ''))) or []: yield t
364+
365+
def validateAttributeValueDir(self, token, tagName, attrName, attrValue):
366+
for t in self.checkEnumeratedValue(token, tagName, attrName, attrValue, frozenset(('ltr', 'rtl'))) or []: yield t
367+
368+
def checkEnumeratedValue(self, token, tagName, attrName, attrValue, enumeratedValues):
369+
if not attrValue and ('' not in enumeratedValues):
370+
yield {"type": "ParseError",
371+
"data": "attribute-value-can-not-be-blank",
372+
"datavars": {"tagName": tagName,
373+
"attributeName": attrName}}
374+
return
361375
attrValue = attrValue.lower()
362-
if attrValue not in frozenset(('true', 'false', '')):
376+
if attrValue not in enumeratedValues:
377+
yield {"type": "ParseError",
378+
"data": "invalid-enumerated-value",
379+
"datavars": {"tagName": tagName,
380+
"attributeName": attrName,
381+
"enumeratedValues": tuple(enumeratedValues)}}
363382
yield {"type": "ParseError",
364383
"data": "invalid-attribute-value",
365384
"datavars": {"tagName": tagName,

0 commit comments

Comments
 (0)