fix microformat parsing author name fails for complicated mf

This commit is contained in:
Wouter Groeneveld 2022-05-04 16:12:10 +02:00
parent f61bda5c5a
commit 8d415d022c
3 changed files with 621 additions and 0 deletions

View File

@ -222,6 +222,9 @@ func DetermineAuthorName(hEntry *microformats.Microformat) string {
if authorName == "" { if authorName == "" {
authorName = Str(hEntry, "author") authorName = Str(hEntry, "author")
} }
if authorName == "" {
authorName = Str(hEntry, "name")
}
return authorName return authorName
} }

View File

@ -9,8 +9,10 @@ import (
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"io/ioutil" "io/ioutil"
"net/http" "net/http"
"strings"
"testing" "testing"
"time" "time"
"willnorris.com/go/microformats"
"brainbaking.com/go-jamming/common" "brainbaking.com/go-jamming/common"
"brainbaking.com/go-jamming/mocks" "brainbaking.com/go-jamming/mocks"
@ -311,6 +313,30 @@ func TestReceiveTargetThatDoesNotPointToTheSourceDoesNothing(t *testing.T) {
assert.Empty(t, repo.GetAllToModerate("brainbaking.com").Data) 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/",
}
cnf := &common.Config{
AllowedWebmentionSources: []string{
"brainbaking.com",
},
}
recv := &Receiver{
Conf: cnf,
}
src, err := ioutil.ReadFile("../../../mocks/indieweb-complicated-data.html")
assert.NoError(t, err)
body := string(src)
data := microformats.Parse(strings.NewReader(body), wm.SourceUrl())
indieweb := recv.convertBodyToIndiewebData(body, wm, data)
assert.Equal(t, "Paul Houlihan", indieweb.Author.Name)
}
func TestProcessSourceBodyAnonymizesBothAuthorPictureAndNameIfComingFromSilo(t *testing.T) { func TestProcessSourceBodyAnonymizesBothAuthorPictureAndNameIfComingFromSilo(t *testing.T) {
wm := mf.Mention{ wm := mf.Mention{
Source: "https://brid.gy/post/twitter/ChrisAldrich/1387130900962443264", Source: "https://brid.gy/post/twitter/ChrisAldrich/1387130900962443264",

File diff suppressed because one or more lines are too long