Minor update

This commit is contained in:
Miroslav Stampar 2026-01-16 16:36:32 +01:00
parent 9d18c81fe0
commit c57f461441
3 changed files with 5 additions and 5 deletions

View file

@ -126,7 +126,7 @@ DEFAULT_OUTPUT_ENCODING = "utf-8"
def _match_css_class(str):
"""Build a RE to match the given CSS class."""
return re.compile(r"(^|.*\s)%s($|\s)" % str)
return re.compile(r"(^|.*\s)%s($|\s)" % re.escape(str))
# First, the classes that represent markup elements.
@ -490,7 +490,7 @@ class NavigableString(text_type, PageElement):
def __str__(self, encoding=DEFAULT_OUTPUT_ENCODING):
# Substitute outgoing XML entities.
data = self.BARE_AMPERSAND_OR_BRACKET.sub(self._sub_entity, self)
if encoding:
if encoding and sys.version_info < (3, 0):
return data.encode(encoding)
else:
return data