Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion tabulate/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -783,7 +783,8 @@ def escape_empty(val):
_esc = r"\x1b"
_csi = rf"{_esc}\["
_osc = rf"{_esc}\]"
_st = rf"{_esc}\\"
# ST: ESC followed by '\' (0x5c), or BEL (0x07) - both are valid OSC terminators
_st = rf"(?:{_esc}\\|\x07)"

_ansi_escape_pat = rf"""
(
Expand Down
23 changes: 23 additions & 0 deletions test/test_regression.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,29 @@ def test_alignment_of_link_cells():
assert_equal(expected, formatted)


def test_alignment_of_bel_terminated_links():
"Regression: BEL-terminated OSC 8 hyperlinks should not inflate column widths."
bel_table = [
("test", "\x1b]8;;target\x07test\x1b]8;;\x07"),
("test", "\x1b]8;;target\x07test\x1b]8;;\x07"),
]
bel_headers = ("test", "\x1b]8;;target\x07test\x1b]8;;\x07")
formatted = tabulate(bel_table, bel_headers, "grid")
expected = "\n".join(
[
"+--------+--------+",
"| test | \x1b]8;;target\x07test\x1b]8;;\x07 |",
"+========+========+",
"| test | \x1b]8;;target\x07test\x1b]8;;\x07 |",
"+--------+--------+",
"| test | \x1b]8;;target\x07test\x1b]8;;\x07 |",
"+--------+--------+",
]
)
print(f"expected: {expected!r}\n\ngot: {formatted!r}\n")
assert_equal(expected, formatted)


def test_alignment_of_link_text_cells():
"Regression: Align links as if they were colorless."
linktable = [
Expand Down