Skip to content

Commit d714b17

Browse files
committed
fix some more table stuff; also introduce a parse error for unexpected end tags in the table phase that we didn't throw until now
--HG-- extra : convert_revision : svn%3Aacbfec75-9323-0410-a652-858a13e371e0/trunk%40484
1 parent ada0ac3 commit d714b17

File tree

1 file changed

+29
-15
lines changed

1 file changed

+29
-15
lines changed

src/html5parser.py

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1087,13 +1087,15 @@ def __init__(self, parser, tree):
10871087
def clearStackToTableContext(self):
10881088
# "clear the stack back to a table context"
10891089
while self.tree.openElements[-1].name not in ("table", "html"):
1090+
self.parser.parseError(_(u"Unexpected implied end tag (" +\
1091+
self.tree.openElements[-1].name + u") in the table phase."))
10901092
self.tree.openElements.pop()
1091-
self.parser.parseError()
10921093
# When the current node is <html> it's an innerHTML case
10931094

10941095
# processing methods
10951096
def processCharacters(self, data):
1096-
self.parser.parseError()
1097+
self.parser.parseError(_(u"Unexpected non-space characters in "
1098+
u"table context caused voodoo mode."))
10971099
# Make all the special element rearranging voodoo kick in
10981100
self.tree.insertFromTable = True
10991101
# Process the character in the "in body" mode
@@ -1131,7 +1133,8 @@ def startTagTable(self, name, attributes):
11311133
self.parser.phase.processStartTag(name, attributes)
11321134

11331135
def startTagOther(self, name, attributes):
1134-
self.parser.parseError()
1136+
self.parser.parseError(_(u"Unexpected start tag (" + name + u") in "
1137+
u"table context caused voodoo mode."))
11351138
# Make all the special element rearranging voodoo kick in
11361139
self.tree.insertFromTable = True
11371140
# Process the start tag in the "in body" mode
@@ -1156,6 +1159,8 @@ def endTagIgnore(self, name):
11561159
"). Ignored."))
11571160

11581161
def endTagOther(self, name):
1162+
self.parser.parseError(_(u"Unexpected end tag (" + name + u") in "
1163+
u"table context caused voodoo mode."))
11591164
# Make all the special element rearranging voodoo kick in
11601165
self.parser.insertFromTable = True
11611166
# Process the end tag in the "in body" mode
@@ -1270,7 +1275,8 @@ def endTagColgroup(self, name):
12701275
self.parser.phase = self.parser.phases["inTable"]
12711276

12721277
def endTagCol(self, name):
1273-
self.parser.parseError()
1278+
self.parser.parseError(_(u"Unexpected end tag (col). "
1279+
u"col has no end tag."))
12741280

12751281
def endTagOther(self, name):
12761282
self.endTagColgroup("colgroup")
@@ -1303,8 +1309,9 @@ def __init__(self, parser, tree):
13031309
def clearStackToTableBodyContext(self):
13041310
while self.tree.openElements[-1].name not in ("tbody", "tfoot",
13051311
"thead", "html"):
1312+
self.parser.parseError(_(u"Unexpected implied end tag (" +\
1313+
self.tree.openElements[-1].name + u") in the table body phase."))
13061314
self.tree.openElements.pop()
1307-
self.parser.parseError()
13081315

13091316
# the rest
13101317
def processCharacters(self,data):
@@ -1316,7 +1323,8 @@ def startTagTr(self, name, attributes):
13161323
self.parser.phase = self.parser.phases["inRow"]
13171324

13181325
def startTagTableCell(self, name, attributes):
1319-
self.parser.parseError()
1326+
self.parser.parseError(_(u"Unexpected table cell start tag (" +\
1327+
name + u") in the table body phase. Ignored."))
13201328
self.startTagTr("tr", {})
13211329
self.parser.phase.processStartTag(name, attributes)
13221330

@@ -1341,7 +1349,8 @@ def endTagTableRowGroup(self, name):
13411349
self.tree.openElements.pop()
13421350
self.parser.phase = self.parser.phases["inTable"]
13431351
else:
1344-
self.parser.parseError()
1352+
self.parser.parseError(_("Unexpected end tag (" + name +\
1353+
") in the table body phase. Ignored."))
13451354

13461355
def endTagTable(self, name):
13471356
if self.tree.elementInScope("tbody", True) or \
@@ -1356,7 +1365,7 @@ def endTagTable(self, name):
13561365

13571366
def endTagIgnore(self, name):
13581367
self.parser.parseError(_("Unexpected end tag (" + name +\
1359-
"). Ignored."))
1368+
") in the table body phase. Ignored."))
13601369

13611370
def endTagOther(self, name):
13621371
self.parser.phases["inTable"].processEndTag(name)
@@ -1386,8 +1395,9 @@ def __init__(self, parser, tree):
13861395
# helper methods (XXX unify this with other table helper methods)
13871396
def clearStackToTableRowContext(self):
13881397
while self.tree.openElements[-1].name not in ("tr", "html"):
1398+
self.parser.parseError(_(u"Unexpected implied end tag (" +\
1399+
self.tree.openElements[-1].name + u") in the row phase."))
13891400
self.tree.openElements.pop()
1390-
self.parser.parseError()
13911401

13921402
# the rest
13931403
def processCharacters(self, data):
@@ -1434,7 +1444,7 @@ def endTagTableRowGroup(self, name):
14341444

14351445
def endTagIgnore(self, name):
14361446
self.parser.parseError(_("Unexpected end tag (" + name +\
1437-
"). Ignored."))
1447+
u") in the row phase. Ignored."))
14381448

14391449
def endTagOther(self, name):
14401450
self.parser.phases["inTable"].processEndTag(name)
@@ -1488,7 +1498,7 @@ def endTagTableCell(self, name):
14881498
if self.tree.elementInScope(name, True):
14891499
self.tree.generateImpliedEndTags(name)
14901500
if self.tree.openElements[-1].name != name:
1491-
self.parser.parseError("Got end tag (" + name +\
1501+
self.parser.parseError("Got table cell end tag (" + name +\
14921502
") while required end tags are missing.")
14931503
while True:
14941504
node = self.tree.openElements.pop()
@@ -1560,7 +1570,8 @@ def startTagOptgroup(self, name, attributes):
15601570
self.tree.insertElement(name, attributes)
15611571

15621572
def startTagSelect(self, name, attributes):
1563-
self.parser.parseError()
1573+
self.parser.parseError(_(u"Unexpected start tag (select) in the "
1574+
u"select phase implies select start tag."))
15641575
self.endTagSelect("select")
15651576

15661577
def startTagOther(self, name, attributes):
@@ -1571,7 +1582,8 @@ def endTagOption(self, name):
15711582
if self.tree.openElements[-1].name == "option":
15721583
self.tree.openElements.pop()
15731584
else:
1574-
self.parser.parseError()
1585+
self.parser.parseError(_(u"Unexpected end tag (option) in the "
1586+
u"select phase. Ignored."))
15751587

15761588
def endTagOptgroup(self, name):
15771589
# </optgroup> implicitly closes <option>
@@ -1583,7 +1595,8 @@ def endTagOptgroup(self, name):
15831595
self.tree.openElements.pop()
15841596
# But nothing else
15851597
else:
1586-
self.parser.parseError()
1598+
self.parser.parseError(_(u"Unexpected end tag (optgroup) in the "
1599+
u"select phase. Ignored."))
15871600

15881601
def endTagSelect(self, name):
15891602
if self.tree.elementInScope(name, True):
@@ -1596,7 +1609,8 @@ def endTagSelect(self, name):
15961609
self.parser.parseError()
15971610

15981611
def endTagTableElements(self, name):
1599-
self.parser.parseError()
1612+
self.parser.parseError(_(u"Unexpected table end tag (" + name +\
1613+
") in the select phase."))
16001614
if self.tree.elementInScope(name, True):
16011615
self.endTagSelect()
16021616
self.parser.phase.processEndTag(name)

0 commit comments

Comments
 (0)