Skip to content

Text.from_ansi exposes OSC 8 payloads with BEL-terminated hyperlinks #4232

Description

@GreedyC
  • I've checked the docs and searched open and closed issues for OSC/BEL/terminator reports.
  • I've checked the FAQ; this reproduction uses the recommended Text.from_ansi conversion.

The bug

Text.from_ansi exposes OSC 8 payload text and loses the link when the sequence ends with BEL. The equivalent ST-terminated sequence works.

from rich.text import Text

for terminator in ("\x1b\\", "\x07"):
    source = f"\x1b]8;;https://example.com{terminator}hello\x1b]8;;{terminator}"
    text = Text.from_ansi(source)
    print(repr(text.plain), [(s.start, s.end, str(s.style)) for s in text.spans])

Actual output:

'hello' [(0, 5, 'link https://example.com')]
'8;;https://example.comhello8;;' []

Expected: both inputs produce plain text hello with the same link span. Xterm documents both BEL and ST as OSC terminators: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h3-Operating-System-Commands

re_ansi in rich/ansi.py currently recognizes ST for its OSC branch, but not BEL. This is distinct from #3561, which measures raw ANSI strings without converting them first.

Platform

Current main commit 9d8f9a3, Python 3.14.6, macOS arm64. Reproduced from the checkout with markdown-it-py and Pygments installed via uv. No terminal rendering is needed to reproduce this.

AI assistance (Codex) was used to investigate and prepare this report; the output above was verified locally. No PR is attached.

Activity

  1. GreedyC commented on Oct 2, 2026

    @GreedyC
    Author

    @willmcgugan Would you approve a small fix for this? I propose accepting BEL as well as ST in the OSC branch of re_ansi, with tests showing Text.from_ansi produces the same plain text and link span for both terminators, including adjacent links. No public API change is needed. I would prepare the patch with Codex assistance and follow the AI policy and PR template; I will wait for your approval before opening the PR.

  2. TomJGooding commented on Oct 2, 2026

    @TomJGooding
    Contributor

    AI assistance (Codex) was used to investigate and prepare this report; the output above was verified locally.

    Today you opened opened 21 other issues and 66 pull requests across different repos, so please don't pretend any human verified this.

    Stop wasting the time of open source maintainers with this AI spam.

  3. GreedyC commented on Oct 2, 2026

    @GreedyC
    Author

    Bro really got mad over a free security patch just because of my PR count 💀. If you're allergic to AI just say it normally instead of crying in the comments. Close the PR and enjoy your vulns, idc.

  4. TomJGooding commented on Oct 2, 2026

    @TomJGooding
    Contributor

    "Please let me know if you would like other suggestions that tone down the edgy 'AI bro' tone, as it does make you sound like a bit of a dick."

  5. GreedyC commented on Oct 2, 2026

    @GreedyC
    Author

    Oki doki My precious Anglophile droogie.

  6. github-actions commented on Oct 2, 2026

    @github-actions

    I hope I helped!

    Consider sponsoring my work on Rich. I give tech support for free, in addition to maintaining Rich and Textual.

    If you like using Rich, you might also enjoy Textual.

    Will McGugan

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions