Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is it possible to force the %-encoding of +? #882

Open
1 task done
grahamc opened this issue Nov 17, 2023 · 1 comment
Open
1 task done

Is it possible to force the %-encoding of +? #882

grahamc opened this issue Nov 17, 2023 · 1 comment
Labels

Comments

@grahamc
Copy link

grahamc commented Nov 17, 2023

  • Note that this crate implements the URL Standard not RFC 1738 or RFC 3986

(but I'm hoping ...)

Describe the bug

This code sample, which is clearly standards-correct behavior emits https://example.com/foo+bar:

let mut url = Url::parse("https://example.com/").unwrap();
url.path_segments_mut().unwrap().push("foo+bar");
    
println!("{}", url);

However, some systems like AWS S3 incorrectly interpret +'s in the path to be spaces:

$ curl 'https://xxx.s3.amazonaws.com/v0.15.1+xxx/xxx'
<?xml version="1.0" encoding="UTF-8"?>
<Error>
  <Code>NoSuchKey</Code>
  <Message>The specified key does not exist.</Message>. 
  <Key>v0.15.1 xxx/xxx</Key>
  ...
</Error>

S3 does decode a %2B as a +, like I'm hoping for.

This puts me in a pickle about how to do this. If I url-encode the + before passing it to URL, it gets (again, properly) encoded to %252B, but S3 doesn't understand that obviously.

Is there a way to get the behavior I'm looking for? Would I have to get the path implement my own string replacement of + with %2B?

@valenting valenting added the bug label Nov 21, 2023
@valenting
Copy link
Collaborator

It seems the issue only happens when using path_segments_mut because of the code here.
I think % was added to PATH_SEGMENT & SPECIAL_PATH_SEGMENT to prevent you from setting the path to %2e which is not allowed.
let x = url::Url::parse("https://example.com/foo%2bbar"); works as expected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants