diff --git a/src/document.c b/src/document.c
index 27c17b2..99596e9 100644
--- a/src/document.c
+++ b/src/document.c
@@ -2225,7 +2225,15 @@ parse_table_row(
cell_start = i;
len = find_emph_char(data + i, size - i, '|');
- i += len ? len : size - i;
+
+ /* Two possibilities for len == 0:
+ 1) No more pipe char found in the current line.
+ 2) The next pipe is right after the current one, i.e. empty cell.
+ For case 1, we skip to the end of line; for case 2 we just continue.
+ */
+ if (len == 0 && data[i] != '|')
+ len = size - i;
+ i += len;
cell_end = i - 1;
diff --git a/test/Tests/Table.html b/test/Tests/Table.html
new file mode 100644
index 0000000..f434598
--- /dev/null
+++ b/test/Tests/Table.html
@@ -0,0 +1,66 @@
+
Standard table
+
+
+
+
+ headline1 |
+ headline2 |
+
+
+
+
+ 123 |
+ |
+
+
+
+
+
+Cell alignment
+
+
+
+
+ headline1 |
+ headline2 |
+ headline3 |
+
+
+
+
+ 123 |
+ |
+ |
+
+
+
+
+
+Malformed table: missing cell at row in body
+
+
+
+
+ headline1 |
+ headline2 |
+ headline3 |
+
+
+
+
+ 12 |
+ |
+ |
+
+
+ 34 |
+ |
+ |
+
+
+ 56 |
+ |
+ |
+
+
+
diff --git a/test/Tests/Table.text b/test/Tests/Table.text
new file mode 100644
index 0000000..37df539
--- /dev/null
+++ b/test/Tests/Table.text
@@ -0,0 +1,21 @@
+# Standard table
+
+|headline1|headline2|
+|---------|---------|
+|123 | |
+
+
+# Cell alignment
+
+|headline1|headline2|headline3|
+|:-------|:------:|------:|
+|123|||
+
+
+# Malformed table: missing cell at row in body
+
+|headline1|headline2|headline3|
+|-------|-------|-------|
+|12
+|34||
+|56|
diff --git a/test/config.json b/test/config.json
index d3e170e..365c7bc 100644
--- a/test/config.json
+++ b/test/config.json
@@ -106,6 +106,11 @@
"input": "Tests/Underline.text",
"output": "Tests/Underline.html",
"flags": ["--underline"]
+ },
+ {
+ "input": "Tests/Table.text",
+ "output": "Tests/Table.html",
+ "flags": ["--tables"]
}
]
}