MindFlavor / AzureSDKForRust

Microsoft Azure SDK for Rust
http://mindflavor.github.io/AzureSDKForRust
Apache License 2.0
160 stars 62 forks source link

url-encoded blob names #317

Closed to266 closed 4 years ago

to266 commented 4 years ago

If a blob contains spaces in its name, they get encoded as + and not %20 when generating a blobl URL. In turn the URL cannot be used until those + are replaced with %20.

Example code:

let client = client::with_access_key(&STORAGE_ACCOUNT, &STORAGE_MASTER_KEY);
let url_string = client
            .generate_signed_blob_url()
            .with_blob_name(blob_name)
            .with_container_name(container_name)
            .with_shared_access_signature(&sas)
            .finalize();

This returns something along the lines of

https://<account>.blob.core.windows.net/<container>/Invoice+name.pdf?<token>

which does not work with just a simple GET (or navigating with a browser).

If the + is replaced with %20, the PDF is displayed as expected

As far as I can see, the consensus is to use + only in the application/x-www-form-urlencoded, which is after the ? in actual URL: https://stackoverflow.com/questions/1634271/url-encoding-the-space-character-or-20

MindFlavor commented 4 years ago

I think you are right. We should percent encode the blob url, not use the application/x-www-form-urlencoded form.

The change should be relegated here:

https://github.com/MindFlavor/AzureSDKForRust/blob/2b48b8ae40c84c4bcf28c2752d8dcd2b2b5ecf3f/azure_sdk_storage_blob/src/blob/mod.rs#L454-L478

I'll try to make the change and get back to you!

MindFlavor commented 4 years ago

@to266 can you please check if the aforementioned PR solves the issue? If yes I will merge it! Thanks!

to266 commented 4 years ago

Yes it does! Thanks for the quick turn-around :)