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

Decoding in paths #339

Closed
koppor opened this issue Jul 20, 2017 · 2 comments
Closed

Decoding in paths #339

koppor opened this issue Jul 20, 2017 · 2 comments

Comments

@koppor
Copy link

koppor commented Jul 20, 2017

Background: I'd like to understand "When to Encode or Decode" from RFC 3986 - and come from google/guava#2078 providing some hints.

When parsing a Host, the hostname is "percent decoded", but when a host is serialized, there is no percent encoding done. Is serializing not the opposite of parsing?

When parsing a URL, the path is encoded. I really wonder, why the path is encoded and not decoded (like in the hostname). During URL serialization there is no encoding or decoding done at all.

Can this difference in the approaches (decoding vs. encoding in parsing) be clarified? Why is no encoding done during serialization?

@TimothyGu
Copy link
Member

No non-ASCII characters are allowed in hosts anyway, so for hosts with percent encoding they could be represented in ASCII, encoded with Punycode, or an invalid host. github%2ecom for example will be parsed and then stored as github.com, %E4%B8%AD%E6%96%87.com (中文.com) as xn--fiq228c.com, while github%00.com is an invalid host. Because they are stored already in a form that is guaranteed to contain only printable ASCII characters, the serialization algorithm does not include another step for percent encoding.

For path, they are encoded during parsing and subsequently stored in an encoded form, so encoding isn't necessary either when serializing. See path state step 2.3:

  1. UTF-8 percent encode c using the path percent-encode set, and append the result to buffer.

@koppor
Copy link
Author

koppor commented Jul 21, 2017

Got it, thanx.

@koppor koppor closed this as completed Jul 21, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants