Skip to content

Commit

Permalink
capricorn86#515@patch: Fixes default pathname when parse URL.
Browse files Browse the repository at this point in the history
  • Loading branch information
Mas0nShi committed Jun 24, 2022
1 parent f9d55eb commit d9570d6
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
4 changes: 2 additions & 2 deletions 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&//=]*)(\?[^#]*)?(#.*)?/;

/**
Expand Down 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 d9570d6

Please sign in to comment.