summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Hill <peter.hill@york.ac.uk>2022-06-13 15:04:23 +0100
committerDavid Lord <davidism@gmail.com>2022-06-13 08:10:02 -0700
commite49d257126d09937b1bf5e2b2173238df729fb13 (patch)
treec3966b17aa2b56e5d3c86b15e52e5ed56715530d
parent0e366be90424816156802b41997b37b5dadd0851 (diff)
downloadmarkupsafe-e49d257126d09937b1bf5e2b2173238df729fb13.tar.gz
match newlines when stripping tags
-rw-r--r--CHANGES.rst3
-rw-r--r--src/markupsafe/__init__.py4
-rw-r--r--tests/test_markupsafe.py2
3 files changed, 7 insertions, 2 deletions
diff --git a/CHANGES.rst b/CHANGES.rst
index ffe462f..e1a558f 100644
--- a/CHANGES.rst
+++ b/CHANGES.rst
@@ -3,6 +3,9 @@ Version 2.1.2
Unreleased
+- Fix ``striptags`` not stripping tags containing newlines.
+ :issue:`310`
+
Version 2.1.1
-------------
diff --git a/src/markupsafe/__init__.py b/src/markupsafe/__init__.py
index a95eb1e..1f9d8cd 100644
--- a/src/markupsafe/__init__.py
+++ b/src/markupsafe/__init__.py
@@ -13,8 +13,8 @@ if t.TYPE_CHECKING:
__version__ = "2.1.2.dev0"
-_strip_comments_re = re.compile(r"<!--.*?-->")
-_strip_tags_re = re.compile(r"<.*?>")
+_strip_comments_re = re.compile(r"<!--.*?-->", re.DOTALL)
+_strip_tags_re = re.compile(r"<.*?>", re.DOTALL)
def _simple_escaping_wrapper(name: str) -> t.Callable[..., "Markup"]:
diff --git a/tests/test_markupsafe.py b/tests/test_markupsafe.py
index 236f35e..a62ebf9 100644
--- a/tests/test_markupsafe.py
+++ b/tests/test_markupsafe.py
@@ -75,6 +75,8 @@ def test_escaping(escape):
"<em>Foo &amp; Bar"
"<!-- inner comment about <em> -->"
"</em>"
+ "<!-- comment\nwith\nnewlines\n-->"
+ "<meta content='tag\nwith\nnewlines'>"
).striptags()
== "Foo & Bar"
)