Repository navigation
Conversation
Handle template start tags with the in-head rules and a simplified in-template phase so <template> before <body> lands in <head>, matching WHATWG insertion-mode requirements. Contents remain ordinary children. Fixes html5lib#595
The in-template phase saved the mode to return to in parser.originalPhase. A nested <template> overwrote it, so closing the outer template left the parser in the in-template phase, and EOF with more than one open template reprocessed EOF in the same phase and hit the assertion in mainLoop. That crash made 25 template.dat tree-walker tests fail on AppVeyor. Keep a stack of saved phases, one per open template, close all open templates at EOF in one step, and only match HTML-namespace template elements.
|
The AppVeyor build (https://ci.appveyor.com/project/gsnedders/html5lib-python/builds/55011423) failed for two reasons, one of them mine. The py37 jobs fail before running anything: the AppVeyor image no longer has Python 3.7 ( py27-base was this PR's fault. It passes on #612 and #615 but here had 75 failures, all template.dat tree-walker tests (25 cases on three tree builders). The parser crashed with the Fixed in 7bb2df9: a stack of saved modes, one per open template, and EOF closes all open templates in one step. Two new tests in test_parser2.py cover nested templates and EOF with several templates open. Locally on Python 3.12 the full suite passes and flake8 is clean. With lxml installed, the tree-construction and tree-walker tests match master plus the new tests. The py37 and py27-optional AppVeyor jobs will still fail for the image reasons above. |
Summary
Before this change, a leading
<template>was treated as an ordinary body element: InHead closed the head and reprocessed the token, so the element landed under<body>.WHATWG says a
templatestart tag in the "in body" insertion mode must use the "in head" rules, which place the element in<head>. This PR:templatein InHead (and the AfterHead / InBody "process in head" lists)Fixes #595
Test plan
pytest html5lib/tests/test_parser2.py(12 passed)<template></template>and<template>hi</template>puttemplateunderhead