Repository: raphlinus/pulldown-cmark (rust)

Issue:
[fuzz result] "table head" with trailing characters getting counted as a header
Something that looks like a table header, but has trailing text, shouldn't count as a table. It plainly contradicts what the spec says here (and disagrees with Pandoc Markdown, Pandoc GFM, actual GFM, and everything else I think to try).

```markdown
|
-|- *
```

<details>

Events from pulldown-cmark:

```rust
"\n |\n-|- *\n" -> [
  Start(Table([]))
    Start(TableHead)
    End(TableHead)
    Start(TableRow)
      Start(TableCell)
        Text(Borrowed("*"))
      End(TableCell)
    End(TableRow)
  End(Table)
]
```

Events from pandoc:

```rust
"\n |\n-|- *\n" -> [
  Start(Paragraph)
    Text(Boxed("|"))
    SoftBreak
    Text(Boxed("-|- *"))
  End(Paragraph)
]
```

Events from commonmark.js:

```rust
"\n |\n-|- *\n" -> [
  Start(Paragraph)
    Text(Boxed("|"))
    SoftBreak
    Text(Boxed("-|- *"))
  End(Paragraph)
]
```

</details>


Pull request:
Reject table delimiter row with unexpected trailing characters
Fixes #813

Patch:
diff --git a/specs/regression.txt b/specs/regression.txt
index 39f00c9..694ef3e 100644
--- a/specs/regression.txt
+++ b/specs/regression.txt
@@ -2163,3 +2163,13 @@ ISSUE 716
 .
 <p><code>\!\"\#\$\%\& \!\"\#\$\%\& \!\"\#\$\%\&</code></pre>
 ````````````````````````````````
+
+ISSUE 813
+
+```````````````````````````````` example
+|
+-|- *
+.
+<p>|
+-|- *</p>
+````````````````````````````````
diff --git a/src/scanners.rs b/src/scanners.rs
index cc2dd15..625db73 100644
--- a/src/scanners.rs
+++ b/src/scanners.rs
@@ -598,9 +598,8 @@ pub(crate) fn scan_table_head(data: &[u8]) -> (usize, Vec<Alignment>) {
                 found_hyphen_in_col = false;
             }
             _ => {
-                cols = vec![];
-                start_col = true;
-                break;
+                // It isn't a table head if it has characters outside the allowed set.
+                return (0, vec![]);
             }
         }
         i += 1;


Test patch:
diff --git a/tests/suite/regression.rs b/tests/suite/regression.rs
index 90069ee..2355616 100644
--- a/tests/suite/regression.rs
+++ b/tests/suite/regression.rs
@@ -2538,7 +2538,7 @@ fn regression_test_156() {
 
     test_markdown_html(original, expected, false, false, false);
 }
-
+  
 #[test]
 fn regression_test_157() {
     let original = r##"`\!\"\#\$\%\&
@@ -2550,3 +2550,15 @@ fn regression_test_157() {
 
     test_markdown_html(original, expected, false, false, false);
 }
+    
+#[test]
+fn regression_test_158() {
+    let original = r##"|
+-|- *
+"##;
+    let expected = r##"<p>|
+-|- *</p>
+"##;
+
+    test_markdown_html(original, expected, false, false, false);
+}