From aef6cf0471d8a550c4b8ca218f43447c82735d02 Mon Sep 17 00:00:00 2001 From: Marcel Horlings Date: Mon, 10 Feb 2020 09:18:06 +0100 Subject: [PATCH] update floki and use explicit parsing of floki (#27) Since the update of Floki to version 0.24.0 other projects get warnings in there tests when using Floki 0.24.0 and oembed together. With this commit the warnings will disapear because it uses the new parse_*/1 functions instead of the old Floki.parse/1 that is now depricated. --- lib/oembed/providers/discoverable_provider.ex | 6 +++++- lib/oembed/providers/pinterest_provider.ex | 6 +++++- mix.exs | 2 +- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/lib/oembed/providers/discoverable_provider.ex b/lib/oembed/providers/discoverable_provider.ex index d8e7d9b..bb264b3 100644 --- a/lib/oembed/providers/discoverable_provider.ex +++ b/lib/oembed/providers/discoverable_provider.ex @@ -28,7 +28,11 @@ defmodule OEmbed.DiscoverableProvider do defp discover(url) do with {:ok, %HTTPoison.Response{body: html}} <- HTTPoison.get(url, [], follow_redirect: true, ssl: [{:versions, [:"tlsv1.2"]}]), - [_ | _] = tags <- Floki.find(html, "head link[type$='json+oembed']"), + [_ | _] = tags <- + html + |> Floki.parse_document() + |> elem(1) + |> Floki.find("head link[type$='json+oembed']"), {"link", attributes, _} <- List.first(tags), %{"href" => href} <- Enum.into(attributes, %{}), oembed_url = %URI{} <- URI.merge(url, href) do diff --git a/lib/oembed/providers/pinterest_provider.ex b/lib/oembed/providers/pinterest_provider.ex index cdf470d..cff5e7b 100644 --- a/lib/oembed/providers/pinterest_provider.ex +++ b/lib/oembed/providers/pinterest_provider.ex @@ -34,7 +34,11 @@ defmodule OEmbed.PinterestProvider do defp get_page_type(url) do with {:ok, %HTTPoison.Response{body: html}} <- HTTPoison.get(url, [], follow_redirect: true, ssl: [{:versions, [:"tlsv1.2"]}]), - [_ | _] = tags <- Floki.find(html, "head meta[property='og:type']"), + [_ | _] = tags <- + html + |> Floki.parse_document() + |> elem(1) + |> Floki.find("head meta[property='og:type']"), {"meta", attributes, _} <- List.first(tags), %{"content" => content} <- Enum.into(attributes, %{}), %{"type" => type} <- Regex.named_captures(~r/^pinterestapp\:(?.+)/, content) do diff --git a/mix.exs b/mix.exs index 255c854..7179b52 100644 --- a/mix.exs +++ b/mix.exs @@ -40,7 +40,7 @@ defmodule OEmbed.Mixfile do defp deps do [ {:httpoison, ">= 0.9.0"}, - {:floki, ">= 0.9.0"}, + {:floki, ">= 0.24.0"}, {:poison, ">= 1.5.0"}, {:exconstructor, ">= 1.0.0"}, {:exvcr, "~> 0.9", only: :test},