Skip to content

Commit 7995adb

Browse files
committed
change processEOF, add error messages and fix a testcase
--HG-- extra : convert_revision : svn%3Aacbfec75-9323-0410-a652-858a13e371e0/trunk%40462
1 parent 60c17a4 commit 7995adb

File tree

1 file changed

+28
-19
lines changed

1 file changed

+28
-19
lines changed

src/html5parser.py

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -234,17 +234,18 @@ def __init__(self, parser, tree):
234234

235235
def processEOF(self):
236236
self.tree.generateImpliedEndTags()
237-
if (len(self.tree.openElements) > 2 or
238-
(len(self.tree.openElements) == 2 and
239-
self.tree.openElements[1].name != "body")):
240-
self.parser.parseError(_("Unexpected end of file. Missing body or html closing tags"))
241-
if self.parser.innerHTML and len(self.tree.openElements) > 1:
242-
# XXX No need to check for "body" because our EOF handling is not
243-
# per specification. (Specification needs an update.)
244-
#
245-
# XXX Need to check this more carefully in the future.
246-
self.parser.parseError()
247-
# Stop parsing
237+
if len(self.tree.openElements) > 2:
238+
self.parser.parseError(_("Unexpected end of file. Missing closing "
239+
"tags"))
240+
elif len(self.tree.openElements) == 2 and\
241+
self.tree.openElements[1].name != "body":
242+
# This happens for framesets or something?
243+
self.parser.parseError(_("XXXXX FRAMESET?"))
244+
elif self.parser.innerHTML and len(self.tree.openElements) > 1 :
245+
# XXX This is not what the specification says. Not sure what to do
246+
# here.
247+
self.parser.parseError(_("XXX innerHTML EOF"))
248+
# Betting ends.
248249

249250
def processComment(self, data):
250251
# For most phases the following is correct. Where it's not it will be
@@ -796,7 +797,8 @@ def startTagMisplaced(self, name, attributes):
796797
"option", "optgroup", "tbody", "td", "tfoot", "th", "thead",
797798
"tr", "noscript"
798799
"""
799-
self.parser.parseError()
800+
self.parser.parseError(_("Unexpected start tag (" + name +\
801+
"). Ignored."))
800802

801803
def startTagNew(self, name, other):
802804
"""New HTML5 elements, "event-source", "section", "nav",
@@ -1133,7 +1135,8 @@ def endTagTable(self, name):
11331135
# innerHTML case
11341136

11351137
def endTagIgnore(self, name):
1136-
self.parser.parseError()
1138+
self.parser.parseError(_("Unexpected end tag (" + name +\
1139+
"). Ignored."))
11371140

11381141
def endTagOther(self, name):
11391142
# Make all the special element rearranging voodoo kick in
@@ -1200,7 +1203,8 @@ def endTagTable(self, name):
12001203
self.parser.phase.processStartTag(name, attributes)
12011204

12021205
def endTagIgnore(self, name):
1203-
self.parser.parseError()
1206+
self.parser.parseError(_("Unexpected end tag (" + name +\
1207+
"). Ignored."))
12041208

12051209
def endTagOther(self, name):
12061210
self.parser.phases["inBody"].processEndTag(name)
@@ -1334,7 +1338,8 @@ def endTagTable(self, name):
13341338
self.parser.parseError()
13351339

13361340
def endTagIgnore(self, name):
1337-
self.parser.parseError()
1341+
self.parser.parseError(_("Unexpected end tag (" + name +\
1342+
"). Ignored."))
13381343

13391344
def endTagOther(self, name):
13401345
self.parser.phases["inTable"].processEndTag(name)
@@ -1411,7 +1416,8 @@ def endTagTableRowGroup(self, name):
14111416
self.parser.parseError()
14121417

14131418
def endTagIgnore(self, name):
1414-
self.parser.parseError()
1419+
self.parser.parseError(_("Unexpected end tag (" + name +\
1420+
"). Ignored."))
14151421

14161422
def endTagOther(self, name):
14171423
self.parser.phases["inTable"].processEndTag(name)
@@ -1465,7 +1471,8 @@ def endTagTableCell(self, name):
14651471
if self.tree.elementInScope(name, True):
14661472
self.tree.generateImpliedEndTags(name)
14671473
if self.tree.openElements[-1].name != name:
1468-
self.parser.parseError()
1474+
self.parser.parseError("Got end tag (" + name +\
1475+
") while required end tags are missing.")
14691476
while True:
14701477
node = self.tree.openElements.pop()
14711478
if node.name == name:
@@ -1475,10 +1482,12 @@ def endTagTableCell(self, name):
14751482
self.tree.clearActiveFormattingElements()
14761483
self.parser.phase = self.parser.phases["inRow"]
14771484
else:
1478-
self.parser.parseError()
1485+
self.parser.parseError(_("Unexpected end tag (" + name +\
1486+
"). Ignored."))
14791487

14801488
def endTagIgnore(self, name):
1481-
self.parser.parseError()
1489+
self.parser.parseError(_("Unexpected end tag (" + name +\
1490+
"). Ignored."))
14821491

14831492
def endTagImply(self, name):
14841493
if self.tree.elementInScope(name, True):

0 commit comments

Comments
 (0)