Skip to content

fix: escape pipes in the moinmoin and textile formats - #502

Open
rahul05ranjan wants to merge 1 commit into
astanin:masterfrom
rahul05ranjan:fix/moinmoin-textile-pipe-escaping
Open

rahul05ranjan wants to merge 1 commit into
astanin:masterfrom
rahul05ranjan:fix/moinmoin-textile-pipe-escaping

Conversation

@rahul05ranjan

Copy link
Copy Markdown

What

tablefmt="moinmoin" and tablefmt="textile" write cell and header values raw, so a literal pipe in the content silently splits the cell — the same class as the mediawiki problem (#499), with these two formats' own separators:

>>> print(tabulate.tabulate([["x | y", "a || b"]], tablefmt="moinmoin"))
||<style="text-align: left;">  x | y    ||<style="text-align: left;">  a || b  ||

|| is the cell separator in MoinMoin tables, so a || b becomes three cells and the style attribute lands on a phantom cell. In textile, | is the separator, so x | y splits in two. Rendered on a real MoinMoin wiki or through a textile converter, the data is silently corrupted.

Fixes #501

Fix

Write literal pipes as &#124; in the values of both formats — MoinMoin and Textile both pass numeric character references through and render them as the literal character:

  • _moin_row_with_attrs escapes cell values (header cells included, they go through the same function).
  • _textile_row_with_attrs escapes data-row values, and the textile header row now uses the existing DataRow.escape_map machinery ({r"|": r"&#124;"}) — the same mechanism GITHUB_ESCAPE_RULES uses for the pipe/github formats.

Values without pipes are byte-identical to before; the existing test_moinmoin* pins are unchanged.

Verification

Two new tests (test_moinmoin_escapes_pipes, test_textile_escapes_pipes) fail on master and pass with this change. Full suite: python3 -m pytest test/ → 351 passed, 17 skipped, zero failures.

A literal | in a cell or header silently split it into extra columns:
|| is the cell separator in MoinMoin tables and | in Textile, so
'a || b' became three cells and the second one's style attribute
landed on a phantom cell. Write literal pipes as &astanin#124; in the values
of both formats, like the mediawiki fix and the escape_map machinery
the github/pipe formats use for their separator.

Fixes astanin#501

Co-authored-by: rahul05ranjan <11793455+rahul05ranjan@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

moinmoin and textile formats: literal pipes in cells silently split columns

1 participant