Skip to content

Commit 9d449c4

Browse files
fix authority normalization (#7)
* fix authority normalization * add normalize userinfo test case * add test to resolveTests array
1 parent 3a669e5 commit 9d449c4

2 files changed

Lines changed: 9 additions & 2 deletions

File tree

lib/index.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,9 @@ const resolveReference = (strategy) => (reference, base) => {
8888

8989
if (resolvedComponents.authority === undefined) {
9090
resolvedComponents.authority = baseComponents.authority;
91+
resolvedComponents.userinfo = baseComponents.userinfo;
92+
resolvedComponents.host = baseComponents.host;
93+
resolvedComponents.port = baseComponents.port;
9194

9295
if (resolvedComponents.path === "") {
9396
resolvedComponents.path = baseComponents.path;
@@ -165,7 +168,10 @@ const getSegment = (path) => {
165168
/** @type (strategy: Strategy, components: API.IdentifierComponents) => string */
166169
const composeIdentifier = (strategy, components) => {
167170
let resolved = components.scheme.toLowerCase() + ":";
168-
resolved += components.authority === undefined ? "" : "//" + components.authority.toLowerCase();
171+
resolved += components.authority === undefined ? "" : "//"
172+
+ (components.userinfo === undefined ? "" : components.userinfo + "@")
173+
+ components.host.toLowerCase()
174+
+ (components.port === undefined ? "" : ":" + components.port);
169175
resolved += strategy.normalizePath(components.path);
170176
resolved += components.query === undefined ? "" : "?" + strategy.normalizeQuery(components.query);
171177
resolved += components.fragment === undefined ? "" : "#" + strategy.normalizeFragment(components.fragment);

lib/resolve-reference.test.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ const resolveTests = [
5454
["http://example.com/b%2Fc/d/e", "", "http://example.com/b%2Fc/d/e"], // Necessary encoding segment
5555
["http://example.com/b%2fc/d/e", "", "http://example.com/b%2Fc/d/e"], // Case normalization of encoding segment
5656
["http://example.com/b?c%2Fd%3Fe", "", "http://example.com/b?c/d?e"], // Unnecessary encoding query
57-
["http://example.com/b", "#c%2Fd%3Fe", "http://example.com/b#c/d?e"] // Unnecessary encoding fragment
57+
["http://example.com/b", "#c%2Fd%3Fe", "http://example.com/b#c/d?e"], // Unnecessary encoding fragment
58+
["Https://JDesrosiers@Example.com", "", "https://JDesrosiers@example.com"] // Case normalization of authority
5859
];
5960

6061
describe("resolveReference", () => {

0 commit comments

Comments
 (0)