From 23419e718023427e14094ecb83ef0bb462a06dee Mon Sep 17 00:00:00 2001 From: nikitosing <32202610+nikitosing@users.noreply.github.com> Date: Fri, 26 Apr 2024 10:52:03 +0300 Subject: [PATCH] fix: Fix incorrect image_url parsing from NFT meta (#9956) * fix: Fix incorrect image_url parsing from NFT meta * Add regression test --- .../lib/block_scout_web/views/nft_helper.ex | 1 + .../api/v2/token_controller_test.exs | 21 +++++++++++++++++++ cspell.json | 5 ++++- 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/apps/block_scout_web/lib/block_scout_web/views/nft_helper.ex b/apps/block_scout_web/lib/block_scout_web/views/nft_helper.ex index a998729ebb..d13ba23676 100644 --- a/apps/block_scout_web/lib/block_scout_web/views/nft_helper.ex +++ b/apps/block_scout_web/lib/block_scout_web/views/nft_helper.ex @@ -54,6 +54,7 @@ defmodule BlockScoutWeb.NFTHelper do def retrieve_image(image_url) do image_url + |> URI.decode() |> URI.encode() |> compose_ipfs_url() end diff --git a/apps/block_scout_web/test/block_scout_web/controllers/api/v2/token_controller_test.exs b/apps/block_scout_web/test/block_scout_web/controllers/api/v2/token_controller_test.exs index f486f61107..dadae9f101 100644 --- a/apps/block_scout_web/test/block_scout_web/controllers/api/v2/token_controller_test.exs +++ b/apps/block_scout_web/test/block_scout_web/controllers/api/v2/token_controller_test.exs @@ -1063,6 +1063,27 @@ defmodule BlockScoutWeb.API.V2.TokenControllerTest do "token" => %{"address" => ^token_address, "name" => ^token_name, "type" => ^token_type} } = json_response(request, 200) end + + # https://github.com/blockscout/blockscout/issues/9906 + test "regression for #9906", %{conn: conn} do + token = insert(:token, type: "ERC-721") + + instance = + insert(:token_instance, + token_id: 0, + token_contract_address_hash: token.contract_address_hash, + metadata: %{ + "image_url" => "ipfs://QmTQBtvkCQKnxbUejwYHrs2G74JR2qFwxPUqRb3BQ6BM3S/gm%20gm%20feelin%20blue%204k.png" + } + ) + + request = get(conn, "/api/v2/tokens/#{token.contract_address.hash}/instances/0") + + assert %{ + "image_url" => + "https://ipfs.io/ipfs/QmTQBtvkCQKnxbUejwYHrs2G74JR2qFwxPUqRb3BQ6BM3S/gm%20gm%20feelin%20blue%204k.png" + } = json_response(request, 200) + end end describe "/tokens/{address_hash}/instances/{token_id}/transfers" do diff --git a/cspell.json b/cspell.json index c22d84c555..5ab24e0e43 100644 --- a/cspell.json +++ b/cspell.json @@ -632,7 +632,10 @@ "zksync", "filecoin", "Filecoin", - "permissionless" + "permissionless", + "feelin", + "KnxbUejwY", + "Btvk" ], "enableFiletypes": [ "dotenv",