From 5fa068687b3e99fb388e9c6bf1d3714a3695afaa Mon Sep 17 00:00:00 2001 From: Joachim Van Herwegen Date: Fri, 16 Oct 2020 10:08:37 +0200 Subject: [PATCH] fix: Correctly parse URL domain --- src/ldp/http/BasicTargetExtractor.ts | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/ldp/http/BasicTargetExtractor.ts b/src/ldp/http/BasicTargetExtractor.ts index 8892c8ab4..4813ade73 100644 --- a/src/ldp/http/BasicTargetExtractor.ts +++ b/src/ldp/http/BasicTargetExtractor.ts @@ -1,5 +1,4 @@ import type { TLSSocket } from 'tls'; -import { format } from 'url'; import type { HttpRequest } from '../../server/HttpRequest'; import { toCanonicalUriPath } from '../../util/Util'; import type { ResourceIdentifier } from '../representation/ResourceIdentifier'; @@ -23,11 +22,11 @@ export class BasicTargetExtractor extends TargetExtractor { throw new Error('Missing host.'); } const isHttps = input.connection && (input.connection as TLSSocket).encrypted; - const path = format({ - protocol: `http${isHttps ? 's' : ''}`, - host: toCanonicalUriPath(input.headers.host), - pathname: toCanonicalUriPath(input.url), - }); + + // URL object applies punycode encoding to domain + const base = `http${isHttps ? 's' : ''}://${input.headers.host}`; + const url = toCanonicalUriPath(input.url); + const path = new URL(url, base).href; return { path }; }