Repository navigation
HTMLParser does not support escapable raw text mode (<textarea> and <title>) #118350
Description
Activity
- addedtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
on Apr 27, 2024 Isn't this because you didn't close your
<style>tag? If I remember correctly style tags go on until</style>is seen regardless of any other tag-like text within the tag, because they may contain text in other languages.@JelleZijlstra , indeed! Closing
<style>allows the snippet to be parsed. However, isn't it inconsistent with the the behaviour observed when parsing other tags?For example, this broken HTML is parsed correctly:
<head><title>Rebelious<h1>Heading<a href="https://example.net">example.net <span>not<a href="https://www.arpa.home">arpa.home<p>Paragraph<h2>and more
The difference is that <style> is a “raw text element”. It cannot contain HTML markup. Most other tags can be followed by other markup. See https://html.spec.whatwg.org/multipage/syntax.html#raw-text-elements
However I believe your HTML with
<title>Rebelious<h1> . . .does trigger a bug. The <title> element is supposed to be an “escapable raw text element”, so<h1>should be counted as part of the raw title text. However it gets parsed as a tag:Encountered a start tag: title
Encountered some data : Rebelious
Encountered a start tag: h1Reacted by savchenko and Łukasz LangaThe original issue (about unclosed
<style>) looks like a duplicate of #86155.- changed the title
[-]HTMLParser stops parsing upon encountering `<style>` tag[/-][+]HTMLParser does not support escapable raw text mode (<textarea> and <title>)[/+]on Jul 14, 2025 - addedtype-securityA security issueA security issue3.11only security fixesonly security fixes3.10 (EOL)end of lifeend of life3.9 (EOL)end of lifeend of life3.12only security fixesonly security fixes3.13only security fixesonly security fixes
on Jul 14, 2025 11 remaining items
- added 3 commits that reference this issue
on Aug 14, 2025 - added a commit that references this issue
on Oct 10, 2025 - added a commit that references this issue
on Oct 20, 2025 - added a commit that references this issue
on Mar 1, 2026
Metadata
Metadata
Assignees
Labels
Projects
- StatusShow more project fieldsDone
Bug report
Bug description:
An example where parsing stops after the
<style color="red">:Changing a single character in the word "style" restores the normal functionality.
CPython versions tested on:
3.11
Operating systems tested on:
Linux
Linked PRs