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

fix: use undecoded @path, @query and @query-param according to the spec #163

Merged
merged 1 commit into from
Jan 16, 2024

Conversation

@AlexanderTar AlexanderTar changed the title feat: Use undecoded @path and @query according to the spec feat: use undecoded @path and @query according to the spec Jan 12, 2024
Copy link
Owner

@dhensby dhensby left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, thanks. Can we add test coverage for this?

@dhensby
Copy link
Owner

dhensby commented Jan 12, 2024

Also, I think this is a fix, not a feat. Would you mind amending the commit message please?

@dhensby
Copy link
Owner

dhensby commented Jan 15, 2024

@AlexanderTar alternatively, if you allow maintainers to make pushes to your PR branch, I can make the amendments to the PR

@AlexanderTar AlexanderTar changed the title feat: use undecoded @path and @query according to the spec fix: use undecoded @path, @query and @query-param according to the spec Jan 15, 2024
@AlexanderTar
Copy link
Contributor Author

Hi @dhensby - Thanks for reviewing

I have added some test cases from the spec and also made sure it is correctly implemented for @query-param

Feel free to merge if you're happy with this

Copy link
Owner

@dhensby dhensby left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having to re-encode the query parameters is leading to inconsistencies and edge-case issues, really we need a way to get our hands on the raw value of the query string parameter and, I'm afraid, that looks like it'll mean manual parsing of the url.search prop.

src/httpbis/index.ts Outdated Show resolved Hide resolved
test/httpbis/httpbis.spec.ts Show resolved Hide resolved
@AlexanderTar
Copy link
Contributor Author

Having to re-encode the query parameters is leading to inconsistencies and edge-case issues, really we need a way to get our hands on the raw value of the query string parameter and, I'm afraid, that looks like it'll mean manual parsing of the url.search prop.

According to the spec, this is the process for deriving @query-param component:

The value of the name parameter and the component value of a single named parameter are calculated by the following process:

  1. Parse the nameString or valueString of the named query parameter defined by the "application/x-www-form-urlencoded parsing" section of [HTMLURL], which is the value after percent-encoded octets are decoded.
  2. Encode the nameString or valueString using the "percent-encode after encoding" process defined by the "application/x-www-form-urlencoded serializing" section of [HTMLURL], which results in an [ASCII] string.
  3. Output the ASCII string

My research showed that searchParams contains a map of URI decoded keys and values, so if name was provided with escaped characters, we have to decode it first before looking up. Similarly, once we found a respective value, it has to be encoded. I would imagine all edge cases should be covered by URL parsing code and as long as they are, we're safe to do encode-decode exercises

@dhensby dhensby merged commit 23f0d1e into dhensby:master Jan 16, 2024
8 checks passed
@dhensby
Copy link
Owner

dhensby commented Jan 16, 2024

Great - thanks for the clarification and the work put into these PRs! 🎉

Copy link

🎉 This PR is included in version 1.0.3 🎉

The release is available on:

Your semantic-release bot 📦🚀

@AlexanderTar AlexanderTar deleted the encoded-uri branch January 16, 2024 10:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants