summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--bs4/css.py7
-rw-r--r--bs4/tests/test_css.py7
2 files changed, 11 insertions, 3 deletions
diff --git a/bs4/css.py b/bs4/css.py
index 5d60267..9b047f8 100644
--- a/bs4/css.py
+++ b/bs4/css.py
@@ -43,13 +43,14 @@ class CSS(object):
@classmethod
def escape(cls, ident):
- """Escape a CSS selector.
+ """Escape a CSS identifier.
- This is a simple wrapper around soupselect.escape().
+ This is a simple wrapper around soupselect.escape(). See the
+ documentation for that function for more information.
"""
if soupsieve is None:
raise NotImplementedError(
- "Cannot escape CSS selectors because the soupsieve package is not installed."
+ "Cannot escape CSS identifiers because the soupsieve package is not installed."
)
return soupsieve.escape(ident)
diff --git a/bs4/tests/test_css.py b/bs4/tests/test_css.py
index 3da9aed..51662ed 100644
--- a/bs4/tests/test_css.py
+++ b/bs4/tests/test_css.py
@@ -2,6 +2,7 @@ import pytest
import types
from bs4 import (
+ CSS,
BeautifulSoup,
ResultSet,
)
@@ -466,3 +467,9 @@ class TestCSSSelectors(SoupTest):
assert isinstance(results, ResultSet)
[result] = results
assert result['id'] == 'header3'
+
+ def test_escape(self):
+ m = CSS.escape
+ assert m(".foo#bar") == '\\.foo\\#bar'
+ assert m("()[]{}") == '\\(\\)\\[\\]\\{\\}'
+ assert m(".foo") == self.soup.css.escape(".foo")