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

net/url: implement url encoding (RFC 3986) #1795

Merged
merged 7 commits into from
Jan 12, 2025
Merged

Conversation

konimarti
Copy link
Contributor

@konimarti konimarti commented Jan 7, 2025

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() 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().

CC: @louis77 as discussed on discord and to keep you in the loop.

@lerno
Copy link
Collaborator

lerno commented Jan 8, 2025

Hmm.. this becomes quite a bit larger, I have to take a longer look at this one. But for now just a small thing: new_parse and temp_parse would be the proper names to conform with the others.

@konimarti
Copy link
Contributor Author

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()`.
@lerno
Copy link
Collaborator

lerno commented Jan 10, 2025

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

@konimarti
Copy link
Contributor Author

konimarti commented Jan 10, 2025

I'll close this PR to come up with a better memory model for this approach.

@konimarti konimarti closed this Jan 10, 2025
@lerno
Copy link
Collaborator

lerno commented Jan 10, 2025

No need to close it. We can discuss improvements.

@lerno lerno reopened this Jan 10, 2025
@lerno lerno merged commit 0e44e63 into c3lang:master Jan 12, 2025
39 checks passed
@konimarti konimarti deleted the escape-url branch January 12, 2025 22:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants