Repository navigation
htmlparser unclosed script tag causes data loss #86155
Description
Activity
When the
closemethod of the HtmlParser is called, any cached text data is generally flushed and passed to adataevent; except when indata_mode. Specifically, if an unclosedscriptorstyletag has been encountered, a call toclosedoes not flush the data.A simple test which demonstrates the issue is attached.
I see that in Lib/html/parser.py#L244-L249 there are two nested if statements which both check for
not self.cdata_elem. Obviously, if we got past the first one, that situation will never exist for the nested one. Somehow this block of code needs a branch for whenself.cdata_elemis True.I should note that the input is invalid HTML. However, the existing behavior results in data loss. Within any other unclosed tag (other than
scriptorstyle) any data is still flushed and passed to adataevent. I would expect the same behavior here. Although, the data escaping behavior should perhaps be applied as it is with data within properly closed tags.- added3.7 (EOL)end of lifeend of life3.8 (EOL)end of lifeend of life3.9 (EOL)end of lifeend of life3.10 (EOL)end of lifeend of lifestdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
on Oct 10, 2020 18 remaining items
- added a commit that references this issue
on Jul 4, 2025 - added 3 commits that reference this issue
on Jul 4, 2025
Metadata
Metadata
Assignees
Labels
Projects
- StatusShow more project fieldsDone
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
Linked PRs