Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HTMLRenderer crashes when special characters appear in digests #35

Open
herrsimon opened this issue Sep 27, 2020 · 3 comments
Open

HTMLRenderer crashes when special characters appear in digests #35

herrsimon opened this issue Sep 27, 2020 · 3 comments
Labels
bug Something isn't working

Comments

@herrsimon
Copy link

Hello,

I just tried to generate a report out of a large number (~5000) of emails and scholar-alert-digest crashed with the following backtrace:

panic: template: layout:29666: unexpected "\\" in command

goroutine 1 [running]:
html/template.Must(...)
        /usr/lib/go/src/html/template/template.go:372
github.com/bzz/scholar-alert-digest/templates.(*HTMLRenderer).Render(0xc006d3f230, 0xafe5e0, 0xc000010018, 0xc00642d5c0, 0xc0022c1470, 0x0)
        /home/simon/git/scholar-alert-digest/templates/templates.go:232 +0x48a
main.main()
        /home/simon/git/scholar-alert-digest/main.go:154 +0x542

Unfortunately I don't know which email actually caused this but it looks like some sort of escaping problem before passing things to the go templating engine.

Command was go run main.go -l scholaralert -authors -html -refs on the current master branch

@issue-label-bot
Copy link

Issue-Label Bot is automatically applying the label bug to this issue, with a confidence of 0.99. Please mark this comment with 👍 or 👎 to give our bot feedback!

Links: app homepage, dashboard and code for this bot.

@issue-label-bot issue-label-bot bot added the bug Something isn't working label Sep 27, 2020
@bzz
Copy link
Owner

bzz commented Oct 21, 2020

Hi @herrsimon ! Thank you for 🐞 report and I'm sorry to hear that it did not work for you and for a delay.
Let me look into it and get back to you here soon.

Meanwhile, could you please check if the same happens with -json (or -mark) instead of -html ?

@reed-foster
Copy link

reed-foster commented Dec 2, 2024

I've seen the same issue caused by LaTeX math expressions in an abstract/title (e.g. \lambda_{{\bf {k}}}). The issue is resolved by using -json or not providing the -html flag. I don't have much familiarity with go, but perhaps there's a way to make the html body a raw string or somehow escape the {{ and }} characters in the html body before passing it to the template? Since the LaTeX isn't getting rendered it'd also seem acceptable to just remove the offending characters in any of the abstracts/titles.

I was able to fix it with:

--- a/templates/templates.go
+++ b/templates/templates.go
@@ -6,6 +6,7 @@ import (
        "bytes"
        "encoding/json"
        "fmt"
+       "strings"
        "html/template"
        "io"
        "log"
@@ -267,7 +268,8 @@ func (r *HTMLRenderer) Render(out io.Writer, st *papers.Stats, unread, read pape
        // rootLayout requires 3 sub-templates
        title := `{{ define "title" }}scholar alert digest{{ end }}`
        style := fmt.Sprintf(`{{ define "style" }}%s{{ end }}`, r.style)
-       body := fmt.Sprintf(`{{ define "body" }}%s{{ end }}`, htmlBuf.String())
+       body_str := strings.Replace(strings.Replace(htmlBuf.String(), "{{", "{ {", -1), "}}", "} }", -1)
+       body := fmt.Sprintf(`{{ define "body" }}%s{{ end }}`, body_str)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants