dfinity / sdk

IC SDK: a Software Development Kit for creating and managing canister smart contracts on the ICP blockchain.
https://internetcomputer.org/developers
Apache License 2.0
170 stars 82 forks source link

fix: url decoding in ic-certified-assets #3767

Closed raymondk closed 2 months ago

raymondk commented 3 months ago

Description

The url_decode function in ic-certified-assets didn't correctly decode some special characters. The code has been changed to decode the "percent strings" to bytes instead of char and then convert the bytes to utf8 strings.

This change is using https://crates.io/crates/percent-encoding - We can then reuse the same library in the response verification library. The crate complies with: https://url.spec.whatwg.org/#percent-decode

Fixes # (SDK-1412)

How Has This Been Tested?

Fixed the existing unit tests and added new unit tests.

One of the tests was broken:

fn main() {
    let c = char::from(230 as u8);
    println!("This is from a char:` {}`", c);

    let s = String::from_utf8([230 as u8].to_vec());
    println!("This from a bytes: `{}`", s.unwrap_or(String::from("ERROR")));
}

Outputs:

This is from a char:`æ`
This from a bytes: `ERROR`

The correct encoding for æ is over two bytes %C3%A6

Checklist: