Skip to content

Commit 77303eb

Browse files
committed
Fixes to the Lint Filter and some enhancements (now takes into account the "computed" content model flag)
--HG-- extra : convert_revision : svn%3Aacbfec75-9323-0410-a652-858a13e371e0/trunk%40686
1 parent 33c7903 commit 77303eb

2 files changed

Lines changed: 19 additions & 10 deletions

File tree

src/filters/lint.py

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ def __iter__(self):
1717
type = token["type"]
1818
if type in ("StartTag", "EmptyTag"):
1919
name = token["name"]
20+
if contentModelFlag != "PCDATA":
21+
raise LintError(_("StartTag not in PCDATA content model flag: %s") % name)
2022
if not isinstance(name, basestring):
2123
raise LintError(_(u"Tag name is not a string: %r") % name)
2224
if not name:
@@ -25,19 +27,20 @@ def __iter__(self):
2527
raise LintError(_(u"Void element reported as StartTag token: %s") % name)
2628
elif type == "EmptyTag" and name not in voidElements:
2729
raise LintError(_(u"Non-void element reported as EmptyTag token: %s") % token["name"])
30+
if type == "StartTag":
31+
open_elements.append(name)
2832
for name, value in token["data"]:
2933
if not isinstance(name, basestring):
3034
raise LintError(_("Attribute name is not a string: %r") % name)
3135
if not name:
3236
raise LintError(_(u"Empty attribute name"))
3337
if not isinstance(value, basestring):
3438
raise LintError(_("Attribute value is not a string: %r") % value)
35-
open_elements.append(name)
3639
if name in cdataElements:
3740
contentModelFlag = "CDATA"
3841
elif name in rcdataElements:
3942
contentModelFlag = "RCDATA"
40-
elif name == "textarea":
43+
elif name == "plaintext":
4144
contentModelFlag = "PLAINTEXT"
4245

4346
elif type == "EndTag":
@@ -48,15 +51,14 @@ def __iter__(self):
4851
raise LintError(_(u"Empty tag name"))
4952
if name in voidElements:
5053
raise LintError(_(u"Void element reported as EndTag token: %s") % name)
51-
if open_elements.pop() != name:
52-
raise LintError(_(u"EndTag does not match StartTag: %s") % name)
54+
start_name = open_elements.pop()
55+
if start_name != name:
56+
raise LintError(_(u"EndTag (%s) does not match StartTag (%s)") % (name, start_name))
5357
contentModelFlag = "PCDATA"
5458

5559
elif type == "Comment":
56-
pass
57-
# XXX: This make tests fail
58-
# if token["data"].find("--") >= 0:
59-
# raise LintError(_(u"Comment contains double-dash"))
60+
if contentModelFlag != "PCDATA":
61+
raise LintError(_("Comment not in PCDATA content model flag"))
6062

6163
elif type in ("Characters", "SpaceCharacters"):
6264
data = token["data"]
@@ -71,12 +73,17 @@ def __iter__(self):
7173

7274
elif type == "Doctype":
7375
name = token["name"]
76+
if contentModelFlag != "PCDATA":
77+
raise LintError(_("Doctype not in PCDATA content model flag: %s") % name)
7478
if not isinstance(name, basestring):
7579
raise LintError(_(u"Tag name is not a string: %r") % name)
7680
if not name:
7781
raise LintError(_(u"Empty tag name"))
7882
# XXX: what to do with token["data"] ?
7983

84+
elif type in ("ParseError", "SerializeError"):
85+
pass
86+
8087
else:
8188
raise LintError(_(u"Unknown token type: %s") % type)
8289

tests/test_treewalkers.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@
1919

2020
import treewalkers
2121
import treebuilders
22-
from filters.lint import Filter as LintFilter
22+
from filters.lint import Filter as LintFilter, LintError
2323
#END RELEASE
2424

2525
#RELEASE add
2626
#import html5lib
2727
#from html5lib import html5parser, serializer, treewalkers, treebuilders
28-
#from html5lib.filters.lint import Filter as LintFilter
28+
#from html5lib.filters.lint import Filter as LintFilter, LintError
2929
#END RELEASE
3030

3131
def PullDOMAdapter(node):
@@ -228,6 +228,8 @@ def runTest(self, innerHTML, input, expected, errors, treeClass):
228228
errorMsg = "\n".join(["\n\nExpected:", expected,
229229
"\nRecieved:", output])
230230
self.assertEquals(expected, output, errorMsg)
231+
except LintError, le:
232+
self.fail(le.message)
231233
except NotImplementedError:
232234
pass # Amnesty for those that confess...
233235

0 commit comments

Comments
 (0)