diff --git a/extension/table.go b/extension/table.go index 617c7a3..c67a1e4 100644 --- a/extension/table.go +++ b/extension/table.go @@ -184,11 +184,11 @@ func (b *tableParagraphTransformer) Transform(node *gast.Paragraph, reader text. func (b *tableParagraphTransformer) parseRow(segment text.Segment, alignments []ast.Alignment, isHeader bool, reader text.Reader, pc parser.Context) *ast.TableRow { source := reader.Source() + segment = segment.TrimLeftSpace(source) + segment = segment.TrimRightSpace(source) line := segment.Value(source) pos := 0 - pos += util.TrimLeftSpaceLength(line) limit := len(line) - limit -= util.TrimRightSpaceLength(line) row := ast.NewTableRow(alignments) if len(line) > 0 && line[pos] == '|' { pos++ diff --git a/extension/table_test.go b/extension/table_test.go index 5ee23e9..21a4663 100644 --- a/extension/table_test.go +++ b/extension/table_test.go @@ -355,3 +355,40 @@ bar | baz t, ) } + +func TestTableFuzzedPanics(t *testing.T) { + markdown := goldmark.New( + goldmark.WithRendererOptions( + html.WithXHTML(), + html.WithUnsafe(), + ), + goldmark.WithExtensions( + NewTable(), + ), + ) + testutil.DoTestCase( + markdown, + testutil.MarkdownTestCase{ + No: 1, + Description: "This should not panic", + Markdown: "* 0\n-|\n\t0", + Expected: `
0 | +
---|
0 | +