Skip to content

Commit e0247f3

Browse files
committed
fixup! Implement InHeadNoscript context
1 parent a3207b0 commit e0247f3

File tree

2 files changed

+28
-5
lines changed

2 files changed

+28
-5
lines changed

html5lib/constants.py

+4
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,10 @@
285285
"Unexpected end tag (%(name)s) before html.",
286286
"unexpected-inhead-noscript-tag":
287287
"Element %(name)s not allowed in a inhead-noscript context",
288+
"eof-in-head-noscript":
289+
"Unexpected end of file. Expected inhead-noscript content",
290+
"char-in-head-noscript":
291+
"Unexpected non-space character. Expected inhead-noscript content",
288292
"XXX-undefined-error":
289293
"Undefined error (this sucks and should be fixed)",
290294
}

html5lib/html5parser.py

+24-5
Original file line numberDiff line numberDiff line change
@@ -827,6 +827,22 @@ def __init__(self, parser, tree):
827827
])
828828
self.endTagHandler.default = self.endTagOther
829829

830+
def processEOF(self):
831+
self.parser.parseError("eof-in-head-noscript")
832+
self.anythingElse()
833+
return True
834+
835+
def processComment(self, token):
836+
return self.parser.phases["inHead"].processComment(token)
837+
838+
def processCharacters(self, token):
839+
self.parser.parseError("char-in-head-noscript")
840+
self.anythingElse()
841+
return token
842+
843+
def processSpaceCharacters(self, token):
844+
return self.parser.phases["inHead"].processSpaceCharacters(token)
845+
830846
def startTagHtml(self, token):
831847
return self.parser.phases["inBody"].processStartTag(token)
832848

@@ -837,23 +853,26 @@ def startTagHeadNoscript(self, token):
837853
self.parser.parseError("unexpected-start-tag", {"name": token["name"]})
838854

839855
def startTagOther(self, token):
840-
return self.anythingElse(token)
856+
self.parser.parseError("unexpected-inhead-noscript-tag", {"name": token["name"]})
857+
self.anythingElse()
858+
return token
841859

842860
def endTagNoscript(self, token):
843861
node = self.parser.tree.openElements.pop()
844862
assert node.name == "noscript", "Expected noscript got %s" % node.name
845863
self.parser.phase = self.parser.phases["inHead"]
846864

847865
def endTagBr(self, token):
848-
return self.anythingElse(token)
866+
self.parser.parseError("unexpected-inhead-noscript-tag", {"name": token["name"]})
867+
self.anythingElse()
868+
return token
849869

850870
def endTagOther(self, token):
851871
self.parser.parseError("unexpected-end-tag", {"name": token["name"]})
852872

853-
def anythingElse(self, token):
854-
self.parser.parseError("unexpected-inhead-noscript-tag", {"name": token["name"]})
873+
def anythingElse(self):
874+
# Caller must raise parse error first!
855875
self.endTagNoscript(impliedTagToken("noscript"))
856-
return token
857876

858877
class AfterHeadPhase(Phase):
859878
def __init__(self, parser, tree):

0 commit comments

Comments
 (0)