Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Soup hyphen in comment #251

Merged
merged 4 commits into from Jul 29, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/lxml/html/soupparser.py
Expand Up @@ -74,7 +74,7 @@ def _parse(source, beautifulsoup, makeelement, **bsargs):
bsargs['convertEntities'] = 'html'
if hasattr(beautifulsoup, "DEFAULT_BUILDER_FEATURES"): # bs4
if 'features' not in bsargs:
bsargs['features'] = ['html.parser'] # use Python html parser
bsargs['features'] = 'html.parser' # use Python html parser
tree = beautifulsoup(source, **bsargs)
root = _convert_tree(tree, makeelement)
# from ET: wrap the document in a html root element, if necessary
Expand Down Expand Up @@ -255,7 +255,7 @@ def convert_tag(bs_node, parent):

@converter(Comment)
def convert_comment(bs_node, parent):
res = etree.Comment(bs_node)
res = html.HtmlComment(bs_node)
if parent is not None:
parent.append(res)
return res
Expand Down
11 changes: 11 additions & 0 deletions src/lxml/html/tests/test_elementsoup.py
Expand Up @@ -45,6 +45,17 @@ def test_wrap_html(self):
tree = self.soupparser.fromstring(html)
self.assertEqual(tostring(tree), res)

def test_comment_hyphen(self):
# These are really invalid XML as per specification
# https://www.w3.org/TR/REC-xml/#sec-comments
html = b'<html><!-- comment -- with double-hyphen --></html>'
tree = self.soupparser.fromstring(html)
self.assertEqual(tostring(tree), html)

html = b'<html><!-- comment ends with hyphen ---></html>'
tree = self.soupparser.fromstring(html)
self.assertEqual(tostring(tree), html)

def test_comment_pi(self):
html = '''<!-- comment -->
<?test asdf?>
Expand Down