summaryrefslogtreecommitdiff
path: root/bs4
diff options
context:
space:
mode:
Diffstat (limited to 'bs4')
-rw-r--r--bs4/__init__.py6
-rw-r--r--bs4/tests/test_tree.py6
2 files changed, 9 insertions, 3 deletions
diff --git a/bs4/__init__.py b/bs4/__init__.py
index a5e7a86..0195bcb 100644
--- a/bs4/__init__.py
+++ b/bs4/__init__.py
@@ -17,7 +17,7 @@ http://www.crummy.com/software/BeautifulSoup/bs4/doc/
"""
__author__ = "Leonard Richardson (leonardr@segfault.org)"
-__version__ = "4.2.0"
+__version__ = "4.2.1"
__copyright__ = "Copyright (c) 2004-2013 Leonard Richardson"
__license__ = "MIT"
@@ -201,9 +201,9 @@ class BeautifulSoup(Tag):
"""Create a new tag associated with this soup."""
return Tag(None, self.builder, name, namespace, nsprefix, attrs)
- def new_string(self, s):
+ def new_string(self, s, subclass=NavigableString):
"""Create a new NavigableString associated with this soup."""
- navigable = NavigableString(s)
+ navigable = subclass(s)
navigable.setup()
return navigable
diff --git a/bs4/tests/test_tree.py b/bs4/tests/test_tree.py
index 4f12d20..c39b3f7 100644
--- a/bs4/tests/test_tree.py
+++ b/bs4/tests/test_tree.py
@@ -689,6 +689,12 @@ class TestTagCreation(SoupTest):
self.assertEqual("foo", s)
self.assertTrue(isinstance(s, NavigableString))
+ def test_new_string_can_create_navigablestring_subclass(self):
+ soup = self.soup("")
+ s = soup.new_string("foo", Comment)
+ self.assertEqual("foo", s)
+ self.assertTrue(isinstance(s, Comment))
+
class TestTreeModification(SoupTest):
def test_attribute_modification(self):