You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
htmlparser unclosed script tag causes data loss #86155
When the close method of the HtmlParser is called, any cached text data is generally flushed and passed to a data event; except when in data_mode. Specifically, if an unclosed script or style tag has been encountered, a call to close does 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 when self.cdata_elem is 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 script or style) any data is still flushed and passed to a data event. 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.
Activity
waylan commentedon Oct 10, 2020
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.18 remaining items
[3.13] gh-86155: Fix data loss after unclosed script or style tag in …
[3.14] gh-86155: Fix data loss after unclosed script or style tag in …
[3.12] pythongh-135661: Fix parsing start and end tags in HTMLParser …
[3.12] gh-135661: Fix parsing start and end tags in HTMLParser accord…
[3.12] pythongh-135661: Fix parsing start and end tags in HTMLParser …
[3.12] pythongh-135661: Fix parsing start and end tags in HTMLParser …
[3.12] pythongh-135661: Fix parsing start and end tags in HTMLParser …
[3.11] gh-135661: Fix parsing start and end tags in HTMLParser accord…
[3.10] gh-135661: Fix parsing start and end tags in HTMLParser accord…
[3.9] gh-135661: Fix parsing start and end tags in HTMLParser accordi…
pythongh-86155: Fix data loss after unclosed script or style tag in H…
[3.9] pythongh-135661: Fix parsing start and end tags in HTMLParser a…
pythongh-86155: Fix data loss after unclosed script or style tag in H…