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'); + }); }); });