Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions tabulate/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -754,8 +754,8 @@ def escape_empty(val):
# - tsv: TBD
# - textile: Replace \n with <br/> (must be well-formed XML)

_multiline_codes = re.compile(r"\r|\n|\r\n")
_multiline_codes_bytes = re.compile(b"\r|\n|\r\n")
_multiline_codes = re.compile(r"\r\n|\r|\n")
_multiline_codes_bytes = re.compile(b"\r\n|\r|\n")

# Handle ANSI escape sequences for both control sequence introducer (CSI) and
# operating system command (OSC). Both of these begin with 0x1b (or octal 033),
Expand Down
18 changes: 18 additions & 0 deletions test/test_regression.py
Original file line number Diff line number Diff line change
Expand Up @@ -598,3 +598,21 @@ def test_github_escape_pipe_character():
result = tabulate([["foo|bar"]], headers=("spam|eggs",), tablefmt="github")
expected = "| spam\\|eggs |\n|:------------|\n| foo\\|bar |"
assert_equal(expected, result)


def test_crlf_multiline_header_matches_lf():
"Regression: CRLF in a header is one line break, same as LF (issue #488)"
expected = "\n".join(
[
"+-----+",
"| A |",
"| B |",
"+=====+",
"| 1 |",
"+-----+",
]
)
lf = tabulate([[1]], headers=["A\nB"], tablefmt="grid")
crlf = tabulate([[1]], headers=["A\r\nB"], tablefmt="grid")
assert_equal(expected, lf)
assert_equal(expected, crlf)