From 360aaec8e82542fa5920b0ded1cc8c44729b4a78 Mon Sep 17 00:00:00 2001 From: James Pyrich Date: Mon, 24 Jun 2019 15:23:39 -0600 Subject: [PATCH] The Open Graph standard allows for additional metadata to be supplied to an image. However, every image description must begin with the strict string "og:image". Hence, only selecting that attribute is sufficient for our uses here. --- lib/link_preview/parsers/opengraph.ex | 2 +- test/support/fixtures/opengraph_example.html | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/link_preview/parsers/opengraph.ex b/lib/link_preview/parsers/opengraph.ex index a7764f8..8aaac21 100644 --- a/lib/link_preview/parsers/opengraph.ex +++ b/lib/link_preview/parsers/opengraph.ex @@ -65,7 +65,7 @@ defmodule LinkPreview.Parsers.Opengraph do images = body |> Floki.parse() - |> Floki.find("meta[property^=\"og:image\"]") + |> Floki.find("meta[property=\"og:image\"]") |> Floki.attribute("content") |> Enum.map(&String.trim(&1)) |> maybe_force_absolute_url(page) diff --git a/test/support/fixtures/opengraph_example.html b/test/support/fixtures/opengraph_example.html index ac33b74..3cb3d82 100644 --- a/test/support/fixtures/opengraph_example.html +++ b/test/support/fixtures/opengraph_example.html @@ -4,9 +4,15 @@ + + + + + + - \ No newline at end of file +