sdk
sdk copied to clipboard
fix: url decoding in ic-certified-assets
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.
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
Warning!
I don't think this PR should be merged as is. It handles decoding differently than the decodeURI function.
// assert_eq!(url_decode("/%%"), Ok("/%".to_string()));
> decodeURI("/%%")
VM301:1 Uncaught URIError: URI malformed
at decodeURI (<anonymous>)
at <anonymous>:1:1
Instead, I suggest we use https://crates.io/crates/percent-encoding-rfc3986 - We can then reuse the same library in the response verification library.
Checklist:
- [ X] The title of this PR complies with Conventional Commits.
- [ ] I have edited the CHANGELOG accordingly.
- [ ] I have made corresponding changes to the documentation.