diff --git a/CHANGES.rst b/CHANGES.rst
index d1074d33..8232d78c 100644
--- a/CHANGES.rst
+++ b/CHANGES.rst
@@ -3,6 +3,8 @@ Version 2.1.5
Unreleased
+- Fix ``striptags`` not collapsing spaces. :issue:`417`
+
Version 2.1.4
-------------
diff --git a/src/markupsafe/__init__.py b/src/markupsafe/__init__.py
index 1e0f0228..e8903bcd 100644
--- a/src/markupsafe/__init__.py
+++ b/src/markupsafe/__init__.py
@@ -158,8 +158,7 @@ def striptags(self) -> str:
>>> Markup("Main »\tAbout").striptags()
'Main ยป About'
"""
- # collapse spaces
- value = " ".join(self.split())
+ value = str(self)
# Look for comments then tags separately. Otherwise, a comment that
# contains a tag would end early, leaving some of the comment behind.
@@ -193,6 +192,8 @@ def striptags(self) -> str:
value = f"{value[:start]}{value[end + 1:]}"
+ # collapse spaces
+ value = " ".join(value.split())
return self.__class__(value).unescape()
@classmethod
diff --git a/tests/test_markupsafe.py b/tests/test_markupsafe.py
index ea9a9187..94bea387 100644
--- a/tests/test_markupsafe.py
+++ b/tests/test_markupsafe.py
@@ -73,7 +73,7 @@ def test_escaping(escape):
Markup(
""
"Foo & Bar"
- ""
+ " \n "
""
""
""