summaryrefslogtreecommitdiff
path: root/bs4
diff options
context:
space:
mode:
Diffstat (limited to 'bs4')
-rw-r--r--bs4/element.py4
-rw-r--r--bs4/testing.py5
-rw-r--r--bs4/tests/test_tree.py4
3 files changed, 11 insertions, 2 deletions
diff --git a/bs4/element.py b/bs4/element.py
index 02fd1b7..e84d70f 100644
--- a/bs4/element.py
+++ b/bs4/element.py
@@ -752,8 +752,8 @@ class Comment(PreformattedString):
class Declaration(PreformattedString):
- PREFIX = u'<!'
- SUFFIX = u'!>'
+ PREFIX = u'<?'
+ SUFFIX = u'?>'
class Doctype(PreformattedString):
diff --git a/bs4/testing.py b/bs4/testing.py
index 9e5e295..847c9fc 100644
--- a/bs4/testing.py
+++ b/bs4/testing.py
@@ -556,6 +556,11 @@ class XMLTreeBuilderSmokeTest(object):
self.assertEqual(
soup.encode(), b'<?xml version="1.0" encoding="utf-8"?>\n<root/>')
+ def test_xml_declaration(self):
+ markup = b"""<?xml version="1.0" encoding="utf8"?>\n<foo/>"""
+ soup = self.soup(markup)
+ self.assertEqual(markup, soup.encode("utf8"))
+
def test_real_xhtml_document(self):
"""A real XHTML document should come out *exactly* the same as it went in."""
markup = b"""<?xml version="1.0" encoding="utf-8"?>
diff --git a/bs4/tests/test_tree.py b/bs4/tests/test_tree.py
index ab21a50..a5cf9e9 100644
--- a/bs4/tests/test_tree.py
+++ b/bs4/tests/test_tree.py
@@ -23,6 +23,7 @@ from bs4.element import (
PY3K,
CData,
Comment,
+ Declaration,
Doctype,
NavigableString,
SoupStrainer,
@@ -1617,6 +1618,9 @@ class TestNavigableStringSubclasses(SoupTest):
soup.insert(1, doctype)
self.assertEqual(soup.encode(), b"<!DOCTYPE foo>\n")
+ def test_declaration(self):
+ d = Declaration("foo")
+ self.assertEqual("<?foo?>", d.output_ready())
class TestSoupSelector(TreeTest):