matrix-org / go-neb

Extensible matrix bot written in Go
Apache License 2.0
285 stars 91 forks source link

Flux RSS Error #299

Open liberodark opened 5 years ago

liberodark commented 5 years ago

Hi,

Use RSS on my room but is not work great with - : The bug is on web and desktop version.

RSS Link on Riot : https://www.domain.ch/link/jeu-vidéo/linux/489499-test+1+4+nano

The correct link https://www.domain.ch/link/jeu-vidéo/linux/489499-test+1+4+nano

Best Regards

liberodark commented 5 years ago

For more information : By Fervex

Looking fast, the blocking part would situate here (line 351-353) :

func itemToHTML(feed *gofeed.Feed, item gofeed.Item) gomatrix.HTMLMessage {
return gomatrix.HTMLMessage{
Body: fmt.Sprintf("%s: %s ( %s )",
html.EscapeString(feed.Title), html.EscapeString(item.Title), html.EscapeString(item.Link)),
MsgType: "m.notice",
Format: "org.matrix.custom.html",
FormattedBody: fmt.Sprintf("<strong>%s</strong>:<br><a href=\"%s\"><strong>%s</strong></a>",
html.EscapeString(feed.Title), html.EscapeString(item.Link), html.EscapeString(item.Title)),
// <strong>FeedTitle</strong>:
// <br>
// <a href="url-of-the-entry"><strong>Title of the Entry</strong></a>
}
}

Looking at one end of the doc : https://golang.org/pkg/html/ and more specifically here https://golang.org/src/html/escape.go?s=4699:4735#L177 We see that UnescapeString et EscapeString are responsible for transformations in html entity. So I'll have to think of seeing a UnescapeString (but no) we only have it for the "description" and "title" on line 328 but not for the link :


i.Title = html.UnescapeString(i.Title)
i.Description = html.UnescapeString(i.Description)

So to test on that side !

liberodark commented 5 years ago

Probable fix with ? :

func itemToHTML(feed *gofeed.Feed, item gofeed.Item) gomatrix.HTMLMessage {
    return gomatrix.HTMLMessage{
        Body: fmt.Sprintf("%s: %s ( %s )",
            html.UnescapeString(feed.Title), html.UnescapeString(item.Title), html.EscapeString(item.Link)),
        MsgType: "m.notice",
        Format: "org.matrix.custom.html",
        FormattedBody: fmt.Sprintf("<strong>%s</strong>:<br><a href=\"%s\"><strong>%s</strong></a>",
            html.EscapeString(feed.Title), html.EscapeString(item.Link), html.EscapeString(item.Title)),
            // <strong>FeedTitle</strong>:
            // <br>
            // <a href="url-of-the-entry"><strong>Title of the Entry</strong></a>
      }
}