fixed webmention discovery
This commit is contained in:
parent
edca158985
commit
de017b86f9
|
@ -177,10 +177,15 @@ func (OwlHtmlParser) GetWebmentionEndpoint(resp *http.Response) (string, error)
|
||||||
findEndpoint = func(n *html.Node) (string, error) {
|
findEndpoint = func(n *html.Node) (string, error) {
|
||||||
if n.Type == html.ElementNode && (n.Data == "link" || n.Data == "a") {
|
if n.Type == html.ElementNode && (n.Data == "link" || n.Data == "a") {
|
||||||
for _, attr := range n.Attr {
|
for _, attr := range n.Attr {
|
||||||
if attr.Key == "rel" && strings.Contains(attr.Val, "webmention") {
|
if attr.Key == "rel" {
|
||||||
for _, attr := range n.Attr {
|
vals := strings.Split(attr.Val, " ")
|
||||||
if attr.Key == "href" {
|
for _, val := range vals {
|
||||||
return attr.Val, nil
|
if val == "webmention" {
|
||||||
|
for _, attr := range n.Attr {
|
||||||
|
if attr.Key == "href" {
|
||||||
|
return attr.Val, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -75,6 +75,19 @@ func TestGetWebmentionEndpointLinkA(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestGetWebmentionEndpointLinkAFakeWebmention(t *testing.T) {
|
||||||
|
html := []byte("<a rel=\"not-webmention\" href=\"http://example.com/foo\" /><a rel=\"webmention\" href=\"http://example.com/webmention\" />")
|
||||||
|
parser := &owl.OwlHtmlParser{}
|
||||||
|
endpoint, err := parser.GetWebmentionEndpoint(constructResponse(html))
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("Unable to parse feed: %v", err)
|
||||||
|
}
|
||||||
|
if endpoint != "http://example.com/webmention" {
|
||||||
|
t.Errorf("Wrong endpoint. Expected %v, got %v", "http://example.com/webmention", endpoint)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestGetWebmentionEndpointLinkHeader(t *testing.T) {
|
func TestGetWebmentionEndpointLinkHeader(t *testing.T) {
|
||||||
html := []byte("")
|
html := []byte("")
|
||||||
parser := &owl.OwlHtmlParser{}
|
parser := &owl.OwlHtmlParser{}
|
||||||
|
|
Loading…
Reference in New Issue