-
-
Notifications
You must be signed in to change notification settings - Fork 519
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: does not warn on unhandled "file://" requests (#1997)
- Loading branch information
1 parent
82ab765
commit 5afedb1
Showing
10 changed files
with
108 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/** | ||
* @vitest-environment jsdom | ||
*/ | ||
import { toPublicUrl } from './toPublicUrl' | ||
|
||
test('returns an absolute request URL withouth search params', () => { | ||
expect(toPublicUrl(new URL('https://test.mswjs.io/path'))).toBe( | ||
'https://test.mswjs.io/path', | ||
) | ||
|
||
expect(toPublicUrl(new URL('http://localhost/path'))).toBe('/path') | ||
|
||
expect(toPublicUrl(new URL('http://localhost/path?foo=bar'))).toBe('/path') | ||
}) | ||
|
||
it('returns a relative URL given the request to the same origin', () => { | ||
expect(toPublicUrl('http://localhost/user')).toBe('/user') | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/** | ||
* Returns a relative URL if the given request URL is relative | ||
* to the current origin. Otherwise returns an absolute URL. | ||
*/ | ||
export function toPublicUrl(url: string | URL): string { | ||
if (typeof location === 'undefined') { | ||
return url.toString() | ||
} | ||
|
||
const urlInstance = url instanceof URL ? url : new URL(url) | ||
|
||
return urlInstance.origin === location.origin | ||
? urlInstance.pathname | ||
: urlInstance.origin + urlInstance.pathname | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters