An HTML comment inside a <template> tag is treated as a TemplateString, not a Comment

Bug #1913406 reported by kosmos342
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Beautiful Soup
Fix Released
Undecided
Unassigned

Bug Description

BeautifulSoup breaks html comments inside "template" tag

>>> from bs4 import BeautifulSoup
>>> print(BeautifulSoup('<template><!--comment--></template>', 'html.parser'))

actual result:
<template>comment</template>

expected result:
<template><!--comment--></template>

Python: 3.6.12 (installed via pyenv)
OS: macOS 11.1
BeautifulSoup: 4.9.3

Revision history for this message
Leonard Richardson (leonardr) wrote :

This is fixed in revision 599. The underlying cause is that most strings inside a <template> tag are supposed to be instantiated with the TemplateString container class. This was interfering with the Comment container class that's used for HTML comments.

Changed in beautifulsoup:
status: New → Fix Committed
summary: - broken html comments in "template" tag
+ An HTML comment inside a <template> tag is treated as a TemplateString,
+ not a Comment
Revision history for this message
Leonard Richardson (leonardr) wrote :

Released in 4.10.0.

Changed in beautifulsoup:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.