mirror of
https://github.com/miniflux/v2.git
synced 2025-08-11 17:51:01 +00:00
fix: URL detection incorrectly capturing newlines in media descriptions
This commit is contained in:
parent
98da7b3f22
commit
a4f672b589
2 changed files with 5 additions and 3 deletions
|
@ -9,7 +9,7 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
var textLinkRegex = regexp.MustCompile(`(?mi)(\bhttps?://[^\s]+)[.]?(?:\s|$)`)
|
var textLinkRegex = regexp.MustCompile(`(?mi)(\bhttps?://[^\s]+)`)
|
||||||
|
|
||||||
// Specs: https://www.rssboard.org/media-rss
|
// Specs: https://www.rssboard.org/media-rss
|
||||||
type MediaItemElement struct {
|
type MediaItemElement struct {
|
||||||
|
@ -154,8 +154,8 @@ func (d *Description) HTML() string {
|
||||||
return d.Description
|
return d.Description
|
||||||
}
|
}
|
||||||
|
|
||||||
content := strings.ReplaceAll(d.Description, "\n", "<br>")
|
content := textLinkRegex.ReplaceAllString(d.Description, `<a href="${1}">${1}</a>`)
|
||||||
return textLinkRegex.ReplaceAllString(content, `<a href="${1}">${1}</a>`)
|
return strings.ReplaceAll(content, "\n", "<br>")
|
||||||
}
|
}
|
||||||
|
|
||||||
// DescriptionList represents a list of "media:description" XML elements.
|
// DescriptionList represents a list of "media:description" XML elements.
|
||||||
|
|
|
@ -83,6 +83,8 @@ func TestDescription(t *testing.T) {
|
||||||
{"", "", ""},
|
{"", "", ""},
|
||||||
{"html", "a <b>c</b>", "a <b>c</b>"},
|
{"html", "a <b>c</b>", "a <b>c</b>"},
|
||||||
{"plain", "a\nhttp://www.example.org/", `a<br><a href="http://www.example.org/">http://www.example.org/</a>`},
|
{"plain", "a\nhttp://www.example.org/", `a<br><a href="http://www.example.org/">http://www.example.org/</a>`},
|
||||||
|
{"plain", "Link: https://example.com/path\n\nAnother: https://example.org",
|
||||||
|
`Link: <a href="https://example.com/path">https://example.com/path</a><br><br>Another: <a href="https://example.org">https://example.org</a>`},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, scenario := range scenarios {
|
for _, scenario := range scenarios {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue