Fix an error occurred when decoding base64 encoded json

pull/6913/head
Cutsin 2 years ago
parent 4c02d3de66
commit fb6e11e217
  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
- [#6833](https://github.com/blockscout/blockscout/pull/6833) - Fix an error occurred when decoding base64 encoded json
- [#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
- [#6893](https://github.com/blockscout/blockscout/pull/6893) - Fix token type definition for multiple interface tokens

@ -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,eyJuYW1lIjogIi54ZGFpIiwgImRlc2NyaXB0aW9uIjogIlB1bmsgRG9tYWlucyBkaWdpdGFsIGlkZW50aXR5IMOvLiBWaXNpdCBodHRwczovL3B1bmsuZG9tYWlucy8iLCAiaW1hZ2UiOiAiZ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kIxYm1zdVpHOXRZV2x1Y3p3dmRHVjRkRDQ4TDNOMlp6ND0ifQ=="
]}
}
assert InstanceMetadataRetriever.fetch_json(data) ==
{:ok,
%{
metadata: %{
"description" => "Punk Domains digital identity ï. Visit https://punk.domains/"
}
}}
end
end
end

Loading…
Cancel
Save