fix: normalize scheme to lowercase (RFC 3986 §6.2.2.1)#182
Merged
Conversation
RFC 3986 §6.2.2.1: the scheme is case-insensitive and should be
normalized to lowercase. `parse()` already lowercases the host but kept
the scheme verbatim, so `parse('HTTP://x').scheme` was `'HTTP'` and
`normalize('HTTP://EXAMPLE.com/')` returned `'HTTP://example.com/'` — an
uppercase scheme next to a lowercased host. `equal()` already compares
schemes case-insensitively, and uri-js returns `'http'`.
Lowercase the scheme at parse time, consistent with the host.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
parse()does not lowercase the scheme, although it already lowercases the host:Why it's a bug
equal()already lowercases the scheme when comparing (fastUri.equal('HTTP://a', 'http://a') === true), so the library already treats the scheme as case-insensitive —normalize()/parse()were just inconsistent with that.uri-js(which this library aims to be iso-compatible with) returns the lowercased scheme:Change
Lowercase the scheme at parse time, next to where the host is already lowercased — one line, no new branches.
Tests
Added
test/scheme-normalization.test.js(red before the change, green after). Fullnpm run test:unitpasses (878).