-
Notifications
You must be signed in to change notification settings - Fork 570
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change
validateTextLinks
to only get URL in markdown links (#1914)
Co-authored-by: Frederik Bolding <[email protected]>
- Loading branch information
1 parent
8d3710b
commit f90233e
Showing
4 changed files
with
47 additions
and
47 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
{ | ||
"branches": 96.02, | ||
"branches": 95.98, | ||
"functions": 99.01, | ||
"lines": 98.69, | ||
"statements": 95.61 | ||
|
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 |
---|---|---|
|
@@ -5,20 +5,24 @@ import { validateTextLinks, validateComponentLinks } from './ui'; | |
describe('validateTextLinks', () => { | ||
it('passes for valid links', () => { | ||
expect(() => | ||
validateTextLinks('https://foo.bar', () => false), | ||
validateTextLinks('[test](https://foo.bar)', () => false), | ||
).not.toThrow(); | ||
|
||
expect(() => | ||
validateTextLinks('mailto:[email protected]', () => false), | ||
validateTextLinks('[test](mailto:[email protected])', () => false), | ||
).not.toThrow(); | ||
|
||
expect(() => | ||
validateTextLinks('[](https://foo.bar)', () => false), | ||
).not.toThrow(); | ||
}); | ||
|
||
it('throws an error if an invalid link is found in text', () => { | ||
expect(() => validateTextLinks('http://foo.bar', () => false)).toThrow( | ||
'Invalid URL: Protocol must be one of: https:, mailto:.', | ||
); | ||
expect(() => | ||
validateTextLinks('[test](http://foo.bar)', () => false), | ||
).toThrow('Invalid URL: Protocol must be one of: https:, mailto:.'); | ||
|
||
expect(() => validateTextLinks('https://foo^bar.bar', () => false)).toThrow( | ||
expect(() => validateTextLinks('[test](foo.bar)', () => false)).toThrow( | ||
'Invalid URL: Unable to parse URL.', | ||
); | ||
}); | ||
|
@@ -46,13 +50,6 @@ describe('validateComponentLinks', () => { | |
it('throws for an unsafe text component', async () => { | ||
const isOnPhishingList = () => true; | ||
|
||
expect(() => | ||
validateComponentLinks( | ||
text('This tests a link: https://foo.bar'), | ||
isOnPhishingList, | ||
), | ||
).toThrow('Invalid URL: The specified URL is not allowed.'); | ||
|
||
expect(() => | ||
validateComponentLinks( | ||
text('This tests a [link](https://foo.bar)'), | ||
|
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