+ Drought
+ + +⭐ I favourited Drought by Wouter Groeneveld on May 16, 2022 — 12:24.
+diff --git a/app/mf/microformats.go b/app/mf/microformats.go index 99f405d..96405c1 100644 --- a/app/mf/microformats.go +++ b/app/mf/microformats.go @@ -192,10 +192,13 @@ func Published(hEntry *microformats.Microformat) string { } func NewAuthor(hEntry *microformats.Microformat, hCard *microformats.Microformat) IndiewebAuthor { - name := DetermineAuthorName(hEntry) - if name == "" { + name := "" + if hCard != nil { name = DetermineAuthorName(hCard) } + if name == "" { + name = DetermineAuthorName(hEntry) + } picture := DetermineAuthorPhoto(hEntry) if picture == "" { picture = DetermineAuthorPhoto(hCard) diff --git a/app/webmention/recv/receive_test.go b/app/webmention/recv/receive_test.go index eada4b8..259008b 100644 --- a/app/webmention/recv/receive_test.go +++ b/app/webmention/recv/receive_test.go @@ -313,28 +313,52 @@ func TestReceiveTargetThatDoesNotPointToTheSourceDoesNothing(t *testing.T) { assert.Empty(t, repo.GetAllToModerate("brainbaking.com").Data) } -func TestConvertBodyToIndiewebDataWithComplicatedDataStillFindsName(t *testing.T) { - wm := mf.Mention{ - Source: "https://pauho.net/2022/05/04/662325/", - Target: "https://brainbaking.com/post/2022/04/cool-things-people-do-with-their-blogs/", +func TestConvertBodyToIndiewebDataWithComplicatedData(t *testing.T) { + cases := []struct { + source string + target string + mockFile string + expectedAuthorName string + }{ + { + "https://pauho.net/2022/05/04/662325/", + "https://brainbaking.com/post/2022/04/cool-things-people-do-with-their-blogs/", + "../../../mocks/indieweb-complicated-data.html", + "Paul Houlihan", + }, + { + "https://ruk.ca/favourite/drought", + "https://brainbaking.com/post/2022/05/drought/", + "../../../mocks/indieweb-hcard-next-to-name.html", + "Peter Rukavina", + }, } + cnf := &common.Config{ AllowedWebmentionSources: []string{ "brainbaking.com", }, } - recv := &Receiver{ Conf: cnf, } - src, err := ioutil.ReadFile("../../../mocks/indieweb-complicated-data.html") - assert.NoError(t, err) + for _, tc := range cases { + t.Run("indieweb author "+tc.expectedAuthorName, func(t *testing.T) { + wm := mf.Mention{ + Source: tc.source, + Target: tc.target, + } - body := string(src) - data := microformats.Parse(strings.NewReader(body), wm.SourceUrl()) - indieweb := recv.convertBodyToIndiewebData(body, wm, data) + src, err := ioutil.ReadFile(tc.mockFile) + assert.NoError(t, err) - assert.Equal(t, "Paul Houlihan", indieweb.Author.Name) + body := string(src) + data := microformats.Parse(strings.NewReader(body), wm.SourceUrl()) + indieweb := recv.convertBodyToIndiewebData(body, wm, data) + + assert.Equal(t, tc.expectedAuthorName, indieweb.Author.Name) + }) + } } func TestProcessSourceBodyAnonymizesBothAuthorPictureAndNameIfComingFromSilo(t *testing.T) { diff --git a/mocks/indieweb-hcard-next-to-name.html b/mocks/indieweb-hcard-next-to-name.html new file mode 100644 index 0000000..33f2ab1 --- /dev/null +++ b/mocks/indieweb-hcard-next-to-name.html @@ -0,0 +1,240 @@ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +⭐ I favourited Drought by Wouter Groeneveld on May 16, 2022 — 12:24.
+