Closed sborrazas closed 2 months ago
I don't think this will solve the issue. I think the problem is, some of the responses are in Chinese/Japanese (e.g. in here: https://mainnet.aeternity.io/mdw/v3/oracles/ok_qJZPXvWPC7G9kFVEqNjj9NAmwMsQcpRu6E3SSCvCQuwfqpMtN/queries ) and if my findings are correct, aescan is using atob
which doesn't decode directly encoded Chinese/Japanese correctly. It seems that a working solution would be to first use URI.encode
and then Base.encode64
and in turn aescan could use decodeURIComponent(window.atob(<response>))
which seems to return the correct response. We could also do that for the query, so that everything is uniform.
@vatanasov I'm pretty sure you don't need any of that, we don't even need the base64 padding. I simply added the padding because it works with all base64 libraries, but it works with atob regardless:
@janmichek can you describe what you are using to decode base64 strings?
This is the frontend function depends if its server (nodejs) or browser rendered, that's what is the condition for
This is the frontend function depends if its server (nodejs) or browser rendered, that's what is the condition for
@janmichek can we switch to using decodeURIComponent(escape(atob(STRING)))
in the browser and Buffer.from(STRING, "base64").toString("utf8")
in the server? Works both with and without padding
console.log(Buffer.from("5oiQ5Yqf5LqGIQ==", "base64").toString('utf8')); // 成功了!
console.log(Buffer.from("5oiQ5Yqf5LqGIQ", "base64").toString('utf8')); // 成功了!
decodeURIComponent
Yea I guess that should work in browser
@sborrazas There seems to be some issue with it, can you check it please?
https://aescan.io/oracles/ok_2fVpBb8j58mNQcVjY7bwUVpBWZv6AySGDjqepNofU8XGGmEN53
The decoding you suggested says its a malformed string, or am I doing something wrong?
@janmichek The response/query values for oracles are just binaries, meaning not all binaries have valid utf8 or ascii representations. Do you know what the utf8 representation for that example you gave should be?
@janmichek The response/query values for oracles are just binaries, meaning not all binaries have valid utf8 or ascii representations. Do you know what the utf8 representation for that example you gave should be?
No, I don't know what the result should be. In that case the current solution is ok, no? I will just sanitize the empty string for N/A. The solution you suggested decodeURIComponent will cause error.
That's right, I would display something for when the binary is not a UTF-8/ASCII representation
It will be fixed in here https://github.com/aeternity/aescan/pull/948
You can close this PR
refs #1931