Skip to content
Merged
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
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## python-markdown2 2.5.6 (not yet released)

- [pull #725] Fix `tables` extra dropping escaped pipes at the end of header and body rows.
- [pull #687] Fix AssertionError hashing HTML blocks spread over multiple lines (#686)
- [pull #692] Fix XSS from code spans in link titles (#691)
- [pull #695] Fix XSS issue from incomplete tags with no attributes (#694)
Expand Down
5 changes: 4 additions & 1 deletion lib/markdown2.py
Original file line number Diff line number Diff line change
Expand Up @@ -4243,7 +4243,10 @@ def run(self, text: str):

@staticmethod
def _split_row(row: str) -> list[str]:
row = row.strip().removeprefix('|').removesuffix('|')
row = row.strip().removeprefix('|')
# An escaped final pipe belongs to the last cell, not the table border.
if not row.endswith(r'\|'):
row = row.removesuffix('|')
return [
re.sub(r'\\\|', '|', cell.strip())
for cell in re.split(r'(?<![\`\\])\|', row)
Expand Down
68 changes: 68 additions & 0 deletions test/tm-cases/tables_escaped_trailing_pipe.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<table>
<thead>
<tr>
<th>Name</th>
<th style="text-align:right;">Operator |</th>
</tr>
</thead>
<tbody>
<tr>
<td>or</td>
<td style="text-align:right;">|</td>
</tr>
<tr>
<td>suffix</td>
<td style="text-align:right;">value|</td>
</tr>
<tr>
<td>repeated</td>
<td style="text-align:right;">||</td>
</tr>
<tr>
<td>emphasis</td>
<td style="text-align:right;"><strong>value</strong>|</td>
</tr>
</tbody>
</table>

<table>
<thead>
<tr>
<th>Name</th>
<th>Operator |</th>
</tr>
</thead>
<tbody>
<tr>
<td>or</td>
<td>|</td>
</tr>
<tr>
<td>suffix</td>
<td>value|</td>
</tr>
</tbody>
</table>

<table>
<thead>
<tr>
<th>Name</th>
<th>Operator |</th>
</tr>
</thead>
<tbody>
<tr>
<td>or</td>
<td>|</td>
</tr>
<tr>
<td>suffix</td>
<td>value|</td>
</tr>
<tr>
<td>empty</td>
<td></td>
</tr>
</tbody>
</table>
1 change: 1 addition & 0 deletions test/tm-cases/tables_escaped_trailing_pipe.opts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"extras": ["tables"]}
17 changes: 17 additions & 0 deletions test/tm-cases/tables_escaped_trailing_pipe.text
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
Name | Operator \|
--- | ---:
or | \|
suffix | value\|
repeated | \|\|
emphasis | **value**\|

| Name | Operator \|
| --- | --- |
| or | \|
| suffix | value\|

| Name | Operator \||
| --- | --- |
| or | \||
| suffix | value\| |
| empty | |