From d9570d64f95c3ead755f469a4da1f83cfb5ac735 Mon Sep 17 00:00:00 2001 From: Mas0nShi Date: Fri, 24 Jun 2022 20:15:53 +0800 Subject: [PATCH 1/2] #515@patch: Fixes default pathname when parse URL. --- packages/happy-dom/src/location/URL.ts | 4 ++-- packages/happy-dom/test/location/URL.test.ts | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/packages/happy-dom/src/location/URL.ts b/packages/happy-dom/src/location/URL.ts index c1fd73c6b..569577d78 100644 --- a/packages/happy-dom/src/location/URL.ts +++ b/packages/happy-dom/src/location/URL.ts @@ -1,5 +1,5 @@ const URL_REGEXP = - /(https?:)\/\/([-a-zA-Z0-9@:%._\+~#=]{2,256}[a-z]{2,6})(:[0-9]*)?([-a-zA-Z0-9@:%_\+.~c&//=]*)(\?[^#]*)?(#.*)?/; + /(https?:)*\/\/([-a-zA-Z0-9@:%._\+~#=]{2,256}[a-z]{2,6})(:[0-9]*)?([-a-zA-Z0-9@:%_\+.~c&//=]*)(\?[^#]*)?(#.*)?/; const PATH_REGEXP = /([-a-zA-Z0-9@:%_\+.~c&//=]*)(\?[^#]*)?(#.*)?/; /** @@ -85,7 +85,7 @@ export default class URL { this.protocol = match[1] || ''; this.hostname = hostnamePart.length > 1 ? hostnamePart[1] : hostnamePart[0]; this.port = match[3] || ''; - this.pathname = match[4] || ''; + this.pathname = match[4] || '/'; this.search = match[5] || ''; this.hash = match[6] || ''; this.username = credentialsPart ? credentialsPart[0] : ''; diff --git a/packages/happy-dom/test/location/URL.test.ts b/packages/happy-dom/test/location/URL.test.ts index 806ab863d..7a8477f49 100644 --- a/packages/happy-dom/test/location/URL.test.ts +++ b/packages/happy-dom/test/location/URL.test.ts @@ -49,5 +49,21 @@ describe('URL', () => { expect(url.host).toBe('google.com:8080'); expect(url.origin).toBe('https://google.com:8080'); }); + it('Parses "https://google.com".', () => { + const formatHref = 'https://google.com/'; + const href = 'https://google.com'; + const url = new URL(href); + expect(url.href).toBe(formatHref); + expect(url.protocol).toBe('https:'); + expect(url.hostname).toBe('google.com'); + expect(url.port).toBe(''); + expect(url.pathname).toBe('/'); + expect(url.search).toBe(''); + expect(url.hash).toBe(''); + expect(url.username).toBe(''); + expect(url.password).toBe(''); + expect(url.host).toBe('google.com'); + expect(url.origin).toBe('https://google.com'); + }); }); }); From a9f739b7108a71842d3059d3ba5f8e28e5fb7036 Mon Sep 17 00:00:00 2001 From: Mas0nShi Date: Fri, 24 Jun 2022 20:17:38 +0800 Subject: [PATCH 2/2] #515@patch: Continue fixes default pathname when parse URL. --- packages/happy-dom/src/location/URL.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/happy-dom/src/location/URL.ts b/packages/happy-dom/src/location/URL.ts index 569577d78..e66e4317f 100644 --- a/packages/happy-dom/src/location/URL.ts +++ b/packages/happy-dom/src/location/URL.ts @@ -1,5 +1,5 @@ const URL_REGEXP = - /(https?:)*\/\/([-a-zA-Z0-9@:%._\+~#=]{2,256}[a-z]{2,6})(:[0-9]*)?([-a-zA-Z0-9@:%_\+.~c&//=]*)(\?[^#]*)?(#.*)?/; + /(https?:)\/\/([-a-zA-Z0-9@:%._\+~#=]{2,256}[a-z]{2,6})(:[0-9]*)?([-a-zA-Z0-9@:%_\+.~c&//=]*)(\?[^#]*)?(#.*)?/; const PATH_REGEXP = /([-a-zA-Z0-9@:%_\+.~c&//=]*)(\?[^#]*)?(#.*)?/; /**