Skip to content

Commit be63155

Browse files
committed
Emit a parse error if no DOCTYPE was seen (when going from initial to the root element phase; if the DOCTYPE has an error emit an error as well (should we?); modify Phase.processEOF to match the spec more accurate; this all should fix some testcases
--HG-- extra : convert_revision : svn%3Aacbfec75-9323-0410-a652-858a13e371e0/trunk%40384
1 parent 2993017 commit be63155

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/parser.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -174,10 +174,11 @@ def __init__(self, parser, tree):
174174

175175
def processEOF(self):
176176
self.tree.generateImpliedEndTags()
177-
if self.parser.innerHTML == False\
178-
or len(self.tree.openElements) > 1:
177+
if self.parser.innerHTML == True and len(self.tree.openElements) > 1:
179178
# XXX No need to check for "body" because our EOF handling is not
180179
# per specification. (Specification needs an update.)
180+
#
181+
# XXX Need to check this more carefully in the future.
181182
self.parser.parseError()
182183
# Stop parsing
183184

@@ -212,29 +213,34 @@ class InitialPhase(Phase):
212213
# "quirks mode". It is expected that a future version of HTML5 will defin
213214
# this.
214215
def processEOF(self):
216+
self.parser.parseError("No DOCTYPE seen.")
215217
self.parser.phase = self.parser.phases["rootElement"]
216218
self.parser.phase.processEOF()
217219

218220
def processComment(self, data):
219221
self.tree.insertComment(data, self.tree.document)
220222

221223
def processDoctype(self, name, error):
224+
if error:
225+
self.parser.parseError("DOCTYPE is in error.")
222226
self.tree.insertDoctype(name)
223227
self.parser.phase = self.parser.phases["rootElement"]
224228

225229
def processSpaceCharacters(self, data):
226230
self.tree.insertText(data, self.tree.document)
227231

228232
def processCharacters(self, data):
229-
self.parser.parseError()
233+
self.parser.parseError("No DOCTYPE seen.")
230234
self.parser.phase = self.parser.phases["rootElement"]
231235
self.parser.phase.processCharacters(data)
232236

233237
def processStartTag(self, name, attributes):
238+
self.parser.parseError("No DOCTYPE seen.")
234239
self.parser.phase = self.parser.phases["rootElement"]
235240
self.parser.phase.processStartTag(name, attributes)
236241

237242
def processEndTag(self, name):
243+
self.parser.parseError("No DOCTYPE seen.")
238244
self.parser.phase = self.parser.phases["rootElement"]
239245
self.parser.phase.processEndTag(name)
240246

0 commit comments

Comments
 (0)