Skip to content

Clarify Url::set_password and percent encoding #1098

@valkum

Description

@valkum

There are already some issues regarding the percent encoding (e.g. #503). I can see that the spec being implemented is https://url.spec.whatwg.org/#userinfo-percent-encode-set. The docs are lacking some info that you need to find by looking up the spec or this issue tracker.

The spec has this note:

Of the possible values for the percentEncodeSet argument only two end up encoding U+0025 (%) and thus give “roundtripable data”: component percent-encode set and application/x-www-form-urlencoded percent-encode set. The other values for the percentEncodeSet argument — which happen to be used by the URL parser — leave U+0025 (%) untouched and as such it needs to be percent-encoded first in order to be properly represented.

I thereby suggest adding something like the following to the docs of Url::set_password:

# Note:
[`Url::set_password()`] uses the [`parser::USERINFO`] encode set which does not 
include `%` per the [URL Standard](http://url.spec.whatwg.org/). This does not create 
roundtripable data if you password contains one or more `%` characters.
Apply a percent encoding to your input using an encode set that includes `%` prior 
to passing it to [`Url::set_password()`].

Something similar might be worth adding to Url::set_username as well. Though usernames tend to contain less special chars nowadays.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions