From f6e93ffd8f78322056696fb5b341025ed344fdac Mon Sep 17 00:00:00 2001 From: yuin Date: Tue, 8 Feb 2022 17:15:15 +0900 Subject: [PATCH] Fix #274, Fix #275 --- _test/extra.txt | 19 +++++++++++++++++++ parser/html_block.go | 2 +- renderer/html/html.go | 1 + testutil/testutil.go | 21 +++++++++++++++------ 4 files changed, 36 insertions(+), 7 deletions(-) diff --git a/_test/extra.txt b/_test/extra.txt index 3cebcb9..374d622 100644 --- a/_test/extra.txt +++ b/_test/extra.txt @@ -684,3 +684,22 @@ This line will be displayed. //= = = = = = = = = = = = = = = = = = = = = = = =// + +53: HTML comment without trailing new lines + OPTIONS: {"trim": true} +//- - - - - - - - -// + +//- - - - - - - - -// + +//= = = = = = = = = = = = = = = = = = = = = = = =// + + +54: Escaped characters followed by a null character + OPTIONS: {"enableEscape": true} +//- - - - - - - - -// +\\\x00\" +//- - - - - - - - -// +

\\\ufffd"

+//= = = = = = = = = = = = = = = = = = = = = = = =// diff --git a/parser/html_block.go b/parser/html_block.go index e6f5a3f..380e723 100644 --- a/parser/html_block.go +++ b/parser/html_block.go @@ -201,7 +201,7 @@ func (b *htmlBlockParser) Continue(node ast.Node, reader text.Reader, pc Context } if bytes.Contains(line, closurePattern) { htmlBlock.ClosureLine = segment - reader.Advance(segment.Len() - 1) + reader.Advance(segment.Len()) return Close } diff --git a/renderer/html/html.go b/renderer/html/html.go index 7f5b9fe..3e6c005 100644 --- a/renderer/html/html.go +++ b/renderer/html/html.go @@ -743,6 +743,7 @@ func (d *defaultWriter) Write(writer util.BufWriter, source []byte) { d.RawWrite(writer, source[n:i]) d.RawWrite(writer, replacementCharacter) n = i + 1 + escaped = false continue } if c == '&' { diff --git a/testutil/testutil.go b/testutil/testutil.go index 4827f5e..f7cb312 100644 --- a/testutil/testutil.go +++ b/testutil/testutil.go @@ -35,22 +35,31 @@ type MarkdownTestCase struct { } func source(t *MarkdownTestCase) string { - if t.Options.EnableEscape { - return string(applyEscapeSequence([]byte(t.Markdown))) + ret := t.Markdown + if t.Options.Trim { + ret = strings.TrimSpace(ret) } - return t.Markdown + if t.Options.EnableEscape { + return string(applyEscapeSequence([]byte(ret))) + } + return ret } func expected(t *MarkdownTestCase) string { - if t.Options.EnableEscape { - return string(applyEscapeSequence([]byte(t.Expected))) + ret := t.Expected + if t.Options.Trim { + ret = strings.TrimSpace(ret) } - return t.Expected + if t.Options.EnableEscape { + return string(applyEscapeSequence([]byte(ret))) + } + return ret } // MarkdownTestCaseOptions represents options for each test case. type MarkdownTestCaseOptions struct { EnableEscape bool + Trim bool } const attributeSeparator = "//- - - - - - - - -//"