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

Add Url::into_encoded_string #540

Keats opened this issue Aug 12, 2019 · 2 comments


Copy link

commented Aug 12, 2019

Which would be the equivalent of urlencode in various languages.
To do something like:

let u = Url::parse("").unwrap();
assert_eq!(u.into_encoded_string(), "")

This comment has been minimized.

Copy link

commented Aug 16, 2019

I think there may be some confusion here. The urlencode function in PHP and Python for example is not intended to encode an entire URL string. Instead, it encodes a string for the purpose of using it as a component of an URL, for example in a query string. The example in PHP docs is:

echo '<a href="mycgi?foo=', urlencode($userinput), '">';

The string looks like a bug, not like a desirable output. Unless it is intended to be part of another URL, something like https::// To do that, existing APIs will already take care of encoding the value correctly:

url.query_pairs_mut().append_pair("next", other_url.as_str());

If you want to encode the URL (or some other string) for the purpose of some other format or protocol that happens to also use percent-encoding, the library for that protocol should take care of the encoding. If you’re implementing that protocol yourself, may be what you’re looking for.


This comment has been minimized.

Copy link

commented Aug 16, 2019

Yeah my bad, I got percent encoding and xml escaping confused in my head somehow.

@Keats Keats closed this Aug 16, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
2 participants
You can’t perform that action at this time.