Skip to content

Commit 724a60f

Browse files
author
Igor Rybak
committedNov 28, 2021
unescape html codes in title
1 parent 4a02f70 commit 724a60f

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed
 

‎habr/feedReader.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ func processItem(item *gofeed.Item) (FeedItem, error) {
8181
if err != nil {
8282
return FeedItem{}, err
8383
}
84-
msg := "<a href=\"" + item.Link + "\">" + item.Title + "</a>\n" + body
84+
msg := "<a href=\"" + item.Link + "\">" + html.UnescapeString(item.Title) + "</a>\n" + body
8585
postID := getPostID(item.Link)
8686

8787
return FeedItem{

‎habr/feedReader_test.go

+15-2
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@ package habr
33
import (
44
"testing"
55

6+
"github.com/mmcdole/gofeed"
67
"github.com/stretchr/testify/assert"
78
)
89

9-
func TestStripTags_PositiveCases(t *testing.T) {
10+
func Test_StripTags_PositiveCases(t *testing.T) {
1011
tests := []struct {
1112
input string
1213
expectedOutput string
@@ -44,13 +45,25 @@ func TestStripTags_PositiveCases(t *testing.T) {
4445
}
4546
}
4647

47-
func TestGetPostID(t *testing.T) {
48+
func Test_GetPostID(t *testing.T) {
4849
input := `https://habr.com/post/413925/?utm_source=habrahabr&utm_medium=rss&utm_campaign=413925`
4950
outputExpected := "413925"
5051
outputActual := getPostID(input)
5152
assert.Equal(t, outputExpected, outputActual)
5253
}
5354

55+
func Test_ProcessItem(t *testing.T) {
56+
item := gofeed.Item{
57+
Title: "стекло &amp; пиксел",
58+
Description: "description",
59+
Link: "http://habr.com/post/1/",
60+
}
61+
feedItem, err := processItem(&item)
62+
assert.Nil(t, err)
63+
assert.Equal(t, "1", feedItem.ID)
64+
assert.Equal(t, `<a href="http://habr.com/post/1/">`+"стекло & пиксел"+`</a>`+"\ndescription", feedItem.Message)
65+
}
66+
5467
// func TestManual(t *testing.T) {
5568
// c := NewHabrReader()
5669
// feeds := c.GetBestFeed()

0 commit comments

Comments
 (0)