-
-
Notifications
You must be signed in to change notification settings - Fork 219
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
net/url: implement url encoding (RFC 3986) #1795
Conversation
Hmm.. this becomes quite a bit larger, I have to take a longer look at this one. But for now just a small thing: |
Yes, please take your time. I'll change the names in the meantime. |
Implement url percent-encoding and -decoding functions according to RFC 3986. Add unit tests. Link: https://datatracker.ietf.org/doc/html/rfc3986
Add encoding and decoding methods to the Url struct components according to RFC 3986. An Url can be parsed from a String with `new_parse()` or `temp_parse()`. The parsed fields are decoded. The only field that is not decoded is `raw_query`. To access the decoded query values, use `Url.query_values()`. `Url.to_string()` will re-assemble the fields into a valid Url string with proper percent-encoded values. If the Url struct fields are filled in manually, use the actual (un-encoded) values. To create a raw query string, initialize an `UrlQueryValues` map, use `UrlQueryValues.add()` to add the query parameters and, finally, call `UrlQueryValues.to_string()`.
It's quite the pity that the non-allocating solution suddenly has so much allocation happening. The whole thing with the query values being separate is because Url wasn't allocating anything too. So now it makes more sense to pull that into URL |
I'll close this PR to come up with a better memory model for this approach. |
No need to close it. We can discuss improvements. |
Implement url percent-encoding and -decoding functions according to RFC 3986.
Link: https://datatracker.ietf.org/doc/html/rfc3986
An Url can be parsed from a String with
new_parse()
ortemp_parse()
. The parsed fields are decoded. The only field that is not decoded israw_query
. To access the decoded query values, useUrl.query_values()
.Url.to_string()
will re-assemble the fields into a valid Url string with proper percent-encoded values.If the Url struct fields are filled in manually, use the actual (un-encoded) values. To create a raw query string, initialize an
UrlQueryValues
map, useUrlQueryValues.add()
to add the query parameters and, finally, callUrlQueryValues.to_string()
.CC: @louis77 as discussed on discord and to keep you in the loop.