diff --git a/block.go b/block.go index 3f4af78..3fa1e92 100644 --- a/block.go +++ b/block.go @@ -515,7 +515,7 @@ func (p *parser) htmlFindEnd(tag string, data []byte) int { return i + skip } -func (p *parser) isEmpty(data []byte) int { +func (*parser) isEmpty(data []byte) int { // it is okay to call isEmpty on an empty buffer if len(data) == 0 { return 0 @@ -530,7 +530,7 @@ func (p *parser) isEmpty(data []byte) int { return i + 1 } -func (p *parser) isHRule(data []byte) bool { +func (*parser) isHRule(data []byte) bool { i := 0 // skip up to three spaces diff --git a/inline_test.go b/inline_test.go index 9fb937b..bcaba09 100644 --- a/inline_test.go +++ b/inline_test.go @@ -59,13 +59,11 @@ func doTestsInlineParam(t *testing.T, tests []string, opts Options, htmlFlags in params HtmlRendererParameters) { // catch and report panics var candidate string - /* - defer func() { - if err := recover(); err != nil { - t.Errorf("\npanic while processing [%#v] (%v)\n", candidate, err) - } - }() - */ + defer func() { + if err := recover(); err != nil { + t.Errorf("\npanic while processing [%#v]: %s\n", candidate, err) + } + }() for i := 0; i+1 < len(tests); i += 2 { input := tests[i] @@ -722,10 +720,6 @@ func TestReferenceLink(t *testing.T) { "[link][ref]\n [ref]: /url/", "

link

\n", - - // Issue 172 in blackfriday - "[]:<", - "

[]:<

\n", } doLinkTestsInline(t, tests) } diff --git a/markdown_test.go b/markdown_test.go new file mode 100644 index 0000000..d897644 --- /dev/null +++ b/markdown_test.go @@ -0,0 +1,75 @@ +// +// Blackfriday Markdown Processor +// Available at http://github.com/russross/blackfriday +// +// Copyright © 2011 Russ Ross . +// Distributed under the Simplified BSD License. +// See README.md for details. +// + +// +// Unit tests for full document parsing and rendering +// + +package blackfriday + +import ( + "testing" +) + +func runMarkdown(input string) string { + return string(MarkdownCommon([]byte(input))) +} + +func doTests(t *testing.T, tests []string) { + // catch and report panics + var candidate string + defer func() { + if err := recover(); err != nil { + t.Errorf("\npanic while processing [%#v]: %s\n", candidate, err) + } + }() + + for i := 0; i+1 < len(tests); i += 2 { + input := tests[i] + candidate = input + expected := tests[i+1] + actual := runMarkdown(candidate) + if actual != expected { + t.Errorf("\nInput [%#v]\nExpected[%#v]\nActual [%#v]", + candidate, expected, actual) + } + + // now test every substring to stress test bounds checking + if !testing.Short() { + for start := 0; start < len(input); start++ { + for end := start + 1; end <= len(input); end++ { + candidate = input[start:end] + _ = runMarkdown(candidate) + } + } + } + } +} + +func TestDocument(t *testing.T) { + var tests = []string{ + // Empty document. + "", + "", + + " ", + "", + + // This shouldn't panic. + // https://github.com/russross/blackfriday/issues/172 + "[]:<", + "

[]:<

\n", + + // This shouldn't panic. + // https://github.com/russross/blackfriday/issues/173 + " [", + "

[

\n", + } + doTests(t, tests) +} diff --git a/ref_test.go b/ref_test.go index 770439c..733a63a 100644 --- a/ref_test.go +++ b/ref_test.go @@ -29,7 +29,7 @@ func doTestsReference(t *testing.T, files []string, flag int) { var candidate string defer func() { if err := recover(); err != nil { - t.Errorf("\npanic while processing [%#v]\n", candidate) + t.Errorf("\npanic while processing [%#v]: %s\n", candidate, err) } }()