Skip to content

mediawiki format: literal pipes in cells/headers silently split columns #499

Open

Description

@rahul05ranjan

What breaks

tablefmt="mediawiki" does not escape | in cell or header content, so any literal pipe silently splits the cell into extra columns on a real MediaWiki wiki:

>>> import tabulate
>>> print(tabulate.tabulate([["x | y"], ["a || b"]], headers=["h | 1"], tablefmt="mediawiki"))
{| class="wikitable" style="text-align: left;"
|+ <!-- caption -->
|-
! h | 1
|-
| x | y
|-
| a || b
|}

Rendered on a wiki, every pipe becomes a column separator: the header row gains a spurious empty column, x | y becomes two cells, and a || b becomes three — the data is silently corrupted.

This is the same class as the escaping the github/pipe formats already do for their separator (x | y is rendered as x \| y there), and the same class prettytable fixed for its MediaWiki emitter (prettytable #544): a literal pipe inside a MediaWiki table cell must be written &#124;.

The header row has the same problem with !: a header cell containing !! splits into extra header columns.

Fix direction

Escape | as &#124; in cell and header values in _mediawiki_row_with_attrs (and ! as &#33; in header rows), the way _html_row_with_attrs HTML-escapes values for the html/unsafe_html formats. Newlines inside cells are a separate, already-tracked multiline-support TODO, so they are out of scope here.

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

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions