Skip to content

Commit

Permalink
Merge pull request #516 from Mas0nShi/515-fixes-default-pathname
Browse files Browse the repository at this point in the history
#515@patch: Fixes default pathname when parse URL.
  • Loading branch information
capricorn86 committed Jun 28, 2022
2 parents 7667c0a + f222ba2 commit 57a8d33
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/happy-dom/src/location/URL.ts
Expand Up @@ -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] : '';
Expand Down
16 changes: 16 additions & 0 deletions packages/happy-dom/test/location/URL.test.ts
Expand Up @@ -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');
});
});
});

0 comments on commit 57a8d33

Please sign in to comment.