Răsfoiți Sursa

fix: URL detection incorrectly capturing newlines in media descriptions

Tim Douglas 8 luni în urmă
părinte
comite
a4f672b589
2 a modificat fișierele cu 5 adăugiri și 3 ștergeri
  1. 3 3
      internal/reader/media/media.go
  2. 2 0
      internal/reader/media/media_test.go

+ 3 - 3
internal/reader/media/media.go

@@ -9,7 +9,7 @@ import (
 	"strings"
 )
 
-var textLinkRegex = regexp.MustCompile(`(?mi)(\bhttps?://[^\s]+)[.]?(?:\s|$)`)
+var textLinkRegex = regexp.MustCompile(`(?mi)(\bhttps?://[^\s]+)`)
 
 // Specs: https://www.rssboard.org/media-rss
 type MediaItemElement struct {
@@ -154,8 +154,8 @@ func (d *Description) HTML() string {
 		return d.Description
 	}
 
-	content := strings.ReplaceAll(d.Description, "\n", "<br>")
-	return textLinkRegex.ReplaceAllString(content, `<a href="${1}">${1}</a>`)
+	content := textLinkRegex.ReplaceAllString(d.Description, `<a href="${1}">${1}</a>`)
+	return strings.ReplaceAll(content, "\n", "<br>")
 }
 
 // DescriptionList represents a list of "media:description" XML elements.

+ 2 - 0
internal/reader/media/media_test.go

@@ -83,6 +83,8 @@ func TestDescription(t *testing.T) {
 		{"", "", ""},
 		{"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", "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 {