Closed malisetti closed 2 years ago
Can confirm that the issue is reproducible by running the following tests. It works when the default parser is used instead.
To run the tests:
$ EMAIL_SMTP_PORT=a EMAIL_SMTP_HOST=a BASE_URL=http://example.com/ EMAIL_NOREPLY=aa DATABASE_URL=aa JWT_SECRET=fff \
go test -run FullMarkdown
which snippet from that tests causes the crash?
which snippet from that tests causes the crash?
The input is not an issue. It's always the first call to ToHTML
that fails.
ok, then to rephrase, what is the most minimal reproduction you can get that fails? Pref. not using any your wrappers
https://go.dev/play/p/6M6Y-OtSnrh
package main
import (
"fmt"
"html"
"github.com/gomarkdown/markdown"
htmlrenderer "github.com/gomarkdown/markdown/html"
mdparser "github.com/gomarkdown/markdown/parser"
)
var inputs = map[string]string{
"# Hello World": `<h1>Hello World</h1>`,
"Hello <b>Beautiful</b> World": `<p>Hello <b>Beautiful</b> World</p>`,
"![](http://example.com/hello.jpg)": `<p><img src="http://example.com/hello.jpg" alt="" /></p>`,
"Go to http://example.com/hello.jpg": `<p>Go to <a href="http://example.com/hello.jpg">http://example.com/hello.jpg</a></p>`,
`-123
-456
-789`: `<p>-123<br />
-456<br />
-789</p>`,
`
- **Option 1**
- *Option 2*
- ~~Option 3~~`: `<ul>
<li><strong>Option 1</strong><br /></li>
<li><em>Option 2</em><br /></li>
<li><del>Option 3</del><br /></li>
</ul>`,
`Please add:
– SEND_SMS
– RECEIVE_SMS
– READ_PHONE_STATE
This will allow to send and receive SMS and get the IMEI No. in our app.
Thanks!`: `<p>Please add:<br />
– SEND_SMS<br />
– RECEIVE_SMS<br />
– READ_PHONE_STATE<br />
This will allow to send and receive SMS and get the IMEI No. in our app.</p>
<p>Thanks!</p>`,
}
func main() {
mdExtns := 0 |
mdparser.Tables |
mdparser.Autolink |
mdparser.FencedCode |
mdparser.Titleblock |
mdparser.Strikethrough |
mdparser.DefinitionLists |
mdparser.NoIntraEmphasis |
mdparser.HardLineBreak
parser := mdparser.NewWithExtensions(mdExtns)
htmlFlags := 0 |
htmlrenderer.UseXHTML |
htmlrenderer.Smartypants |
htmlrenderer.SmartypantsFractions |
htmlrenderer.SmartypantsDashes |
htmlrenderer.SmartypantsLatexDashes
fullRenderer := htmlrenderer.NewRenderer(htmlrenderer.RendererOptions{Flags: htmlFlags})
for input, _ := range inputs {
fmt.Printf("%q\n", input)
sanitizedInput := html.EscapeString(input)
markdown.ToHTML([]byte(sanitizedInput), parser, fullRenderer)
}
}
thanks. You're reusing the parser the creates the crash.
for input, _ := range inputs {
fmt.Printf("%q\n", input)
sanitizedInput := gohtml.EscapeString(input)
parser := parser.NewWithExtensions(mdExtns)
ToHTML([]byte(sanitizedInput), parser, fullRenderer)
}
makes the crash go away.
this should be documented, but unsure
Why a renderer can be reused but not a parser? That looks like a bug.
We could reset the state but no one did the work and there's almost zero benefit over creating a new parser.
I have no plans on working on that.
This benchmark fails with following errors