Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F85949224
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Authored By
Unknown
Size
3 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/lib/pleroma/web/rich_media/parser.ex b/lib/pleroma/web/rich_media/parser.ex
index e4e03319e..51028612d 100644
--- a/lib/pleroma/web/rich_media/parser.ex
+++ b/lib/pleroma/web/rich_media/parser.ex
@@ -32,7 +32,8 @@ defmodule Pleroma.Web.RichMedia.Parser do
end
defp parse_url(url) do
- with {:ok, data} <- OEmbed.direct_lookup(url),
+ with true <- OEmbed in parsers(),
+ {:ok, data} <- OEmbed.direct_lookup(url),
{:ok, data} <- data |> clean_parsed_data() |> check_parsed_data() do
{:ok, data}
else
diff --git a/lib/pleroma/web/rich_media/parsers/o_embed.ex b/lib/pleroma/web/rich_media/parsers/o_embed.ex
index e1c9f7888..995f1c963 100644
--- a/lib/pleroma/web/rich_media/parsers/o_embed.ex
+++ b/lib/pleroma/web/rich_media/parsers/o_embed.ex
@@ -43,7 +43,7 @@ defmodule Pleroma.Web.RichMedia.Parsers.OEmbed do
defp get_oembed_data(url) do
with {:ok, json} <- Pleroma.Web.RichMedia.Helpers.rich_media_get(url, accept: :json),
- {:ok, %{"html" => html} = data} <- Jason.decode(json) do
+ {:ok, %{"html" => html} = data} when is_binary(html) <- Jason.decode(json) do
{:ok,
data
|> Map.put("html", Pleroma.HTML.filter_tags(html))
diff --git a/test/pleroma/web/rich_media/parser_test.exs b/test/pleroma/web/rich_media/parser_test.exs
index 2a38ee733..e1c377011 100644
--- a/test/pleroma/web/rich_media/parser_test.exs
+++ b/test/pleroma/web/rich_media/parser_test.exs
@@ -118,6 +118,12 @@ defmodule Pleroma.Web.RichMedia.ParserTest do
Parser.parse("https://youtu.be/YOUTUBETEST1")
end
+ test "is skipped when the OEmbed parser is disabled" do
+ clear_config([:rich_media, :parsers], [Pleroma.Web.RichMedia.Parsers.TwitterCard])
+
+ assert {:error, _} = Parser.parse("https://www.youtube.com/watch?v=YOUTUBETEST1")
+ end
+
test "falls back to the page when the oEmbed endpoint fails" do
assert {:ok, %{"title" => "The Rock"}} =
Parser.parse("https://www.youtube.com/watch?v=NOOEMBED")
@@ -128,6 +134,10 @@ defmodule Pleroma.Web.RichMedia.ParserTest do
assert {:error, :invalid_metadata} = Parser.parse("https://example.com/oembed-internal")
end
+ test "ignores oEmbed data where html is not a string" do
+ assert {:error, :invalid_metadata} = Parser.parse("https://example.com/oembed-null-html")
+ end
+
test "rejects invalid OGP data" do
assert {:error, _} = Parser.parse("https://example.com/malformed")
end
diff --git a/test/support/http_request_mock.ex b/test/support/http_request_mock.ex
index 0c3ab0c60..04d9bdbb9 100644
--- a/test/support/http_request_mock.ex
+++ b/test/support/http_request_mock.ex
@@ -1497,6 +1497,18 @@ defmodule HttpRequestMock do
{:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/rich_media/oembed.html")}}
end
+ def get("https://example.com/oembed-null-html", _, _, _) do
+ {:ok,
+ %Tesla.Env{
+ status: 200,
+ body: ~s(<link type="application/json+oembed" href="https://example.com/oembed-null.json">)
+ }}
+ end
+
+ def get("https://example.com/oembed-null.json", _, _, _) do
+ {:ok, %Tesla.Env{status: 200, body: ~s({"title": "Null", "html": null})}}
+ end
+
def get("https://example.com/oembed-internal", _, _, _) do
{:ok,
%Tesla.Env{status: 200, body: File.read!("test/fixtures/rich_media/oembed_internal.html")}}
@@ -1805,6 +1817,8 @@ defmodule HttpRequestMock do
"https://example.com/non-ogp",
"https://example.com/oembed",
"https://example.com/oembed-internal",
+ "https://example.com/oembed-null-html",
+ "https://example.com/oembed-null.json",
"http://127.0.0.1:9200/internal.json",
"https://example.com/ogp",
"https://example.com/ogp-missing-data",
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Tue, Nov 17, 8:54 PM (15 h, 52 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1839801
Default Alt Text
(3 KB)
Attached To
Mode
rPUBE pleroma-upstream
Attached
Detach File
Event Timeline