Skip to content

CRLF in multiline headers adds an extra blank row #488

Open

Description

@agammann

A header containing Windows-style CRLF (\r\n) renders with an extra blank header row. The same header with LF renders as two lines.

Reproduced on current main (268615a5c27dc40e5c22454c07b44d5c50410da0) with CPython 3.14.8 on Windows:

from tabulate import tabulate

print(tabulate([[1]], headers=['A\nB'], tablefmt='grid'))
print(tabulate([[1]], headers=['A\r\nB'], tablefmt='grid'))

The LF header renders as:

+-----+
|   A |
|   B |
+=====+
|   1 |
+-----+

The CRLF header instead renders as:

+-----+
|   A |
|     |
|   B |
+=====+
|   1 |
+-----+

Expected: CRLF and LF represent one line break and produce the same two-line header. A data cell containing A\r\nB renders as two lines, so this appears specific to header alignment.

_align_header splits using _multiline_codes = re.compile(r'\r|\n|\r\n'); the \r alternative consumes the first half of a CRLF before the \r\n alternative can match.

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