Merge pull request #6913 from cutsin/master-pr-6913

Fix an error occurred when decoding base64 encoded json
pull/6922/head
Victor Baranov 2 years ago committed by GitHub
commit 7a704d8420
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      CHANGELOG.md
  2. 4
      apps/explorer/lib/explorer/token/instance_metadata_retriever.ex
  3. 18
      apps/explorer/test/explorer/token/instance_metadata_retriever_test.exs

@ -7,6 +7,7 @@
### Fixes
- [#6912](https://github.com/blockscout/blockscout/pull/6912) - Docker compose fix exposed ports
- [#6913](https://github.com/blockscout/blockscout/pull/6913) - Fix an error occurred when decoding base64 encoded json
- [#6911](https://github.com/blockscout/blockscout/pull/6911) - Fix bugs in verification API v2
- [#6891](https://github.com/blockscout/blockscout/pull/6891) - Fix read contract for geth
- [#6889](https://github.com/blockscout/blockscout/pull/6889) - Fix Internal Server Error on tx input decoding

@ -169,7 +169,7 @@ defmodule Explorer.Token.InstanceMetadataRetriever do
end
def fetch_json(%{@token_uri => {:ok, ["data:application/json;base64," <> base64_encoded_json]}}, hex_token_id) do
case Base.url_decode64(base64_encoded_json) do
case Base.decode64(base64_encoded_json) do
{:ok, base64_decoded} ->
fetch_json(%{@token_uri => {:ok, [base64_decoded]}}, hex_token_id)
@ -190,7 +190,7 @@ defmodule Explorer.Token.InstanceMetadataRetriever do
end
def fetch_json(%{@uri => {:ok, ["data:application/json;base64," <> base64_encoded_json]}}, hex_token_id) do
case Base.url_decode64(base64_encoded_json) do
case Base.decode64(base64_encoded_json) do
{:ok, base64_decoded} ->
fetch_json(%{@uri => {:ok, [base64_decoded]}}, hex_token_id)

@ -307,5 +307,23 @@ defmodule Explorer.Token.InstanceMetadataRetrieverTest do
}
}}
end
test "decodes base64 encoded json file (with unicode string) in tokenURI" do
data = %{
"c87b56dd" =>
{:ok,
[
"data:application/json;base64,eyJkZXNjcmlwdGlvbiI6ICJQdW5rIERvbWFpbnMgZGlnaXRhbCBpZGVudGl0eSDDry4gVmlzaXQgaHR0cHM6Ly9wdW5rLmRvbWFpbnMvIn0="
]}
}
assert InstanceMetadataRetriever.fetch_json(data) ==
{:ok,
%{
metadata: %{
"description" => "Punk Domains digital identity ï. Visit https://punk.domains/"
}
}}
end
end
end

Loading…
Cancel
Save