Skip to content

Commit 369feef

Browse files
authored
Merge pull request #5557 from Textualize/fix-slash-r
strip control codes
2 parents 3f049f4 + 9f01549 commit 369feef

File tree

3 files changed

+8
-0
lines changed

3 files changed

+8
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1111

1212
- Fixed smooth scrolling broken on iTerm over SSH https://github.com/Textualize/textual/pull/5551
1313
- Fixed height of auto container which contains auto height children https://github.com/Textualize/textual/pull/5552
14+
- Fixed `Content.from_markup` not stripping control codes https://github.com/Textualize/textual/pull/5557
1415
- Fixed `delta_x` and `delta_y` in mouse events when smooth scrolling is enabled https://github.com/Textualize/textual/pull/5556
1516

1617
### Added

src/textual/content.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ def from_markup(cls, markup: str | Content, **variables: object) -> Content:
193193
if variables:
194194
raise ValueError("A literal string is require to substitute variables.")
195195
return markup
196+
markup = _strip_control_codes(markup)
196197
from textual.markup import to_content
197198

198199
content = to_content(markup, template_variables=variables or None)

tests/test_content.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,3 +223,9 @@ def test_escape():
223223
content = Content.from_markup("\\[bold]Not really bold")
224224
assert content.plain == "[bold]Not really bold"
225225
assert content.spans == []
226+
227+
228+
def test_strip_control_codes():
229+
"""Test that control codes are removed from content."""
230+
assert Content("foo\r\nbar").plain == "foo\nbar"
231+
assert Content.from_markup("foo\r\nbar").plain == "foo\nbar"

0 commit comments

Comments
 (0)