fix: escape rich markup in ls table cells

This commit is contained in:
randogoth 2026-10-24 21:56:15 +03:00
parent 921f06b4fa
commit 3a9f3a2fcd
2 changed files with 11 additions and 1 deletions

View file

@ -79,7 +79,8 @@ def mktable(query: str, index: dict, filter=None, trunc_len: int=25):
else:
elements.append(None)
table.add_row(*elements)
# Cells are read as rich markup, so [brackets] in names and notes need escaping
table.add_row(*[escape(element) if element else element for element in elements])
console.print(table)
else:
console.print(f":thinking_face: [red]No results found for [white]{query}")

View file

@ -170,3 +170,12 @@ def test_cmd_user_errors_exit_with_1(cwd, monkeypatch, capsys):
main()
assert exit.value.code == 1
assert "File missing.mp3 doesn't exist." in capsys.readouterr().out
def test_cmd_list_shows_square_brackets(cwd, monkeypatch, capsys):
(cwd / 'a [demo].mp3').touch()
OrvaniTag().add('a [demo].mp3', '#lofi', 'note', '[with]', 'brackets')
monkeypatch.setattr(sys, 'argv', ['otag', 'ls', '#lofi'])
main()
out = capsys.readouterr().out
assert 'a [demo].mp3' in out and '[with]' in out