Skip to content

Commit 60a6512

Browse files
authored
striptags collapses spaces correctly (#418)
2 parents 73e6a48 + 0b6bee0 commit 60a6512

File tree

3 files changed

+6
-3
lines changed

3 files changed

+6
-3
lines changed

CHANGES.rst

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ Version 2.1.5
33

44
Unreleased
55

6+
- Fix ``striptags`` not collapsing spaces. :issue:`417`
7+
68

79
Version 2.1.4
810
-------------

src/markupsafe/__init__.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,7 @@ def striptags(self) -> str:
158158
>>> Markup("Main &raquo;\t<em>About</em>").striptags()
159159
'Main » About'
160160
"""
161-
# collapse spaces
162-
value = " ".join(self.split())
161+
value = str(self)
163162

164163
# Look for comments then tags separately. Otherwise, a comment that
165164
# contains a tag would end early, leaving some of the comment behind.
@@ -193,6 +192,8 @@ def striptags(self) -> str:
193192

194193
value = f"{value[:start]}{value[end + 1:]}"
195194

195+
# collapse spaces
196+
value = " ".join(value.split())
196197
return self.__class__(value).unescape()
197198

198199
@classmethod

tests/test_markupsafe.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ def test_escaping(escape):
7373
Markup(
7474
"<!-- outer comment -->"
7575
"<em>Foo &amp; Bar"
76-
"<!-- inner comment about <em> -->"
76+
" <!-- inner comment about <em> -->\n "
7777
"</em>"
7878
"<!-- comment\nwith\nnewlines\n-->"
7979
"<meta content='tag\nwith\nnewlines'>"

0 commit comments

Comments
 (0)