diff --git a/CHANGELOG.md b/CHANGELOG.md index 9b0eecd76..a359a1ad1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## Unreleased + +### Fixed + +- Strip problematic private escape sequences (like `\x1b7`) + ## [13.7.0] - 2023-11-15 ### Added diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index 22b1be0db..51375d0d1 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -25,6 +25,7 @@ The following people have contributed to the development of Rich: - [Kenneth Hoste](https://github.com/boegel) - [Lanqing Huang](https://github.com/lqhuang) - [Finn Hughes](https://github.com/finnhughes) +- [Logan Hunt](https://github.com/dosisod) - [Ionite](https://github.com/ionite34) - [Josh Karpel](https://github.com/JoshKarpel) - [Jan Katins](https://github.com/jankatins) diff --git a/rich/ansi.py b/rich/ansi.py index 66365e653..7de86ce50 100644 --- a/rich/ansi.py +++ b/rich/ansi.py @@ -9,6 +9,7 @@ re_ansi = re.compile( r""" +(?:\x1b[0-?])| (?:\x1b\](.*?)\x1b\\)| (?:\x1b([(@-Z\\-_]|\[[0-?]*[ -/]*[@-~])) """, diff --git a/tests/test_ansi.py b/tests/test_ansi.py index ae87cde17..d81f6459f 100644 --- a/tests/test_ansi.py +++ b/tests/test_ansi.py @@ -68,3 +68,17 @@ def test_decode_issue_2688(ansi_bytes, expected_text): text = Text.from_ansi(ansi_bytes.decode()) assert str(text) == expected_text + + +@pytest.mark.parametrize("code", [*"0123456789:;<=>?"]) +def test_strip_private_escape_sequences(code): + text = Text.from_ansi(f"\x1b{code}x") + + console = Console(force_terminal=True) + + with console.capture() as capture: + console.print(text) + + expected = "x\n" + + assert capture.get() == expected