Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(getAbsoluteUrl): fix full url check (#982)
* feat(getAbsoluteUrl): handle url schemes, relative urls without leading slashes * feat(getAbsoluteUrl): convert path start with colon to absolute URL
- Loading branch information
Showing
5 changed files
with
60 additions
and
4 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 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,32 @@ | ||
/** | ||
* @jest-environment node | ||
*/ | ||
import { isAbsoluteUrl } from './isAbsoluteUrl' | ||
|
||
test('returns true for the "http" scheme', () => { | ||
expect(isAbsoluteUrl('http://www.domain.com')).toEqual(true) | ||
}) | ||
|
||
test('returns true for the "https" scheme', () => { | ||
expect(isAbsoluteUrl('https://www.domain.com')).toEqual(true) | ||
}) | ||
|
||
test('returns true for the "ws" scheme', () => { | ||
expect(isAbsoluteUrl('ws://www.domain.com')).toEqual(true) | ||
}) | ||
|
||
test('returns true for the "ftp" scheme', () => { | ||
expect(isAbsoluteUrl('ftp://www.domain.com')).toEqual(true) | ||
}) | ||
|
||
test('returns true for the custom scheme', () => { | ||
expect(isAbsoluteUrl('web+my://www.example.com')).toEqual(true) | ||
}) | ||
|
||
test('returns false for the relative URL', () => { | ||
expect(isAbsoluteUrl('/test')).toEqual(false) | ||
}) | ||
|
||
test('returns false for the relative URL without a leading slash', () => { | ||
expect(isAbsoluteUrl('test')).toEqual(false) | ||
}) |
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,6 @@ | ||
/** | ||
* Determines if the given URL string is an absolute URL. | ||
*/ | ||
export function isAbsoluteUrl(url: string): boolean { | ||
return /^([a-z][a-z\d\+\-\.]*:)?\/\//i.test(url) | ||
} |