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

normalized_user and normalized_password should not percent-encode characters in sub-delims #548

Open
Yihao-G opened this issue Jan 10, 2025 · 0 comments

Comments

@Yihao-G
Copy link

Yihao-G commented Jan 10, 2025

The sub-delims characters should not be percent-encoded by the normalized_user and normalized_password methods in Addressable::URI as they are valid characters according to RFC 3986:

   userinfo      = *( unreserved / pct-encoded / sub-delims / ":" )
   pct-encoded   = "%" HEXDIG HEXDIG
   unreserved    = ALPHA / DIGIT / "-" / "." / "_" / "~"
   sub-delims    = "!" / "$" / "&" / "'" / "(" / ")"
                 / "*" / "+" / "," / ";" / "="

Current behaviour:

>> Addressable::URI.parse('https://u$er!:[email protected]').normalized_user
=> "u%24er%21"
>> Addressable::URI.parse('https://u$er!:[email protected]').normalized_password
=> "pa%24s"
>> Addressable::URI.parse('https://u$er!:[email protected]').normalized_userinfo
=> "u%24er%21:pa%24s"

Expected behaviour:

>> Addressable::URI.parse('https://u$er!:[email protected]').normalized_user
=> "u$er!"
>> Addressable::URI.parse('https://u$er!:[email protected]').normalized_password
=> "pa$s"
>> Addressable::URI.parse('https://u$er!:[email protected]').normalized_userinfo
=> "u$er!:pa$s"

The characters are encoded in the following two places:

Addressable::URI.normalize_component(
self.user.strip,
Addressable::URI::NormalizeCharacterClasses::UNRESERVED
)

Addressable::URI.normalize_component(
self.password.strip,
Addressable::URI::NormalizeCharacterClasses::UNRESERVED
)

The second parameter to be passed to Addressable::URI.normalize_component should be /[^#{CharacterClasses::UNRESERVED + CharacterClasses::SUB_DELIMS}]/ instead of just /[^#{CharacterClasses::UNRESERVED}]/

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

No branches or pull requests

1 participant