Skip to content

Commit

Permalink
handle empty XCardsImage cases
Browse files Browse the repository at this point in the history
  • Loading branch information
aafeher committed Feb 4, 2025
1 parent b8b08a8 commit 2da42df
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 0 deletions.
4 changes: 4 additions & 0 deletions extract_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -965,6 +965,10 @@ func TestExtractor_Extract(t *testing.T) {
URL: `https://github.com/aafeher/go-microdata-extract`,
Description: `X Cards with image`,
XCardsImage: []extract.XCardsImage{
{
URL: "",
Width: 1200,
},
{
URL: "https://picsum.photos/200/300",
},
Expand Down
5 changes: 5 additions & 0 deletions extractors/xcards.go
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,11 @@ func handleXCardsImageProperty(xc *XCards, parts []string, content string) {
}
lastIdx := len(xc.XCardsImage) - 1

if lastIdx < 0 {
xc.XCardsImage = append(xc.XCardsImage, XCardsImage{})
lastIdx = 0
}

if len(parts) == 2 {
xc.XCardsImage[lastIdx].URL = content
return
Expand Down
1 change: 1 addition & 0 deletions test/test-17-xcards-image.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<meta name="twitter:title" content="go-microdata-extract" />
<meta name="twitter:url" content="https://github.com/aafeher/go-microdata-extract" />
<meta name="twitter:description" content="X Cards with image" />
<meta name="twitter:image:width" content="1200" />
<meta name="twitter:image" content="https://picsum.photos/200/300" />
<meta name="twitter:image" content="https://picsum.photos/210/310" />
<meta name="twitter:image:secure_url" content="https://picsum.photos/210/310" />
Expand Down

0 comments on commit 2da42df

Please sign in to comment.