Skip to content

CSV fields are interpreted as console markup, changing data or aborting rendering #147

Open

Description

@philppplik

CSV cells containing bracketed text are passed through Rich markup parsing. Valid CSV data can therefore disappear or abort the command rather than render literally.

Environment

  • rich-cli distribution 1.8.1, default-branch commit 46f4d2469097be395558768714a5f07ebccf1412
  • Rich 12.6.0, Click 8.5.0
  • Linux x86_64, Python 3.10.12

Reproduction

printf 'name,value\n[red]literal[/red],2\n' | rich --csv -
printf 'name,value\n[/bold],2\n' | rich --csv -
echo "exit=$?"

I also reproduced the first case from a .csv file and inspected its SVG export.

Actual behavior

The first table shows only literal, in red. The actual CSV value [red]literal[/red] is changed, even though this is CSV mode, not --print mode.

The second command fails with:

failed to print resource: closing tag '[/bold]' at position 0 doesn't match any
open tag
exit=255

A standalone field [not-a-style] also renders as an empty cell.

Expected behavior

CSV header and data values should render as literal text. Brackets and strings resembling markup should not remove data or cause a valid CSV to fail.

Cause

render_csv() in src/rich_cli/__main__.py passes raw strings to Table.add_column() and Table.add_row(). Rich's table/console path interprets those strings as markup. Wrapping the values in Text or escaping them before handing them to the table would keep the cells literal.

These commands were run locally with the versions above. This is separate from empty-CSV handling in #143 and delimiter detection: both fixtures parse into ordinary two-column CSV rows.

Activity

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