-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixes URL validation method for cross-browser support
In Firefox this will throw an Error: ``` new URL("https://www. example .com ") ``` In Chrome the same action will result in: ``` https://www.%20example%20.com ``` As a result the try/catch pattern used for validation rarely flagged links on Chrome. The approach in this commit uses a lenient regular expression to validate URLs. A URL just needs a protocol, a domain, and optionally a path. The domain and protocol have a limited character set.
- Loading branch information
1 parent
6c30b07
commit 77b60ae
Showing
5 changed files
with
76 additions
and
15 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 |
---|---|---|
|
@@ -59,6 +59,56 @@ describe('validators: invalid-links', () => { | |
})).toEqual([]); | ||
}); | ||
|
||
test('passes if field with mailto link', () => { | ||
expect(fn({ | ||
components: { | ||
[uri]: { a: '<a href="mailto:[email protected]">Lorem ipsum dolor sit amet</a>, consectetur adipisicing elit' } | ||
}, | ||
schemas: { | ||
[name]: { | ||
a: { | ||
_has: ['text'] | ||
} | ||
} | ||
} | ||
})).toEqual([]); | ||
}); | ||
|
||
test('passes if field with ftp link', () => { | ||
expect(fn({ | ||
components: { | ||
[uri]: { a: '<a href="ftp://1.1.1.1:21/test">Lorem ipsum dolor sit amet</a>, consectetur adipisicing elit' } | ||
}, | ||
schemas: { | ||
[name]: { | ||
a: { | ||
_has: ['text'] | ||
} | ||
} | ||
} | ||
})).toEqual([]); | ||
}); | ||
|
||
test('fails if field relative link', () => { | ||
expect(fn({ | ||
components: { | ||
[uri]: { a: '<a href="/subscribe">Lorem ipsum dolor sit amet</a>, consectetur adipisicing elit' } | ||
}, | ||
schemas: { | ||
[name]: { | ||
a: { | ||
_has: ['text'] | ||
} | ||
} | ||
} | ||
})).toEqual([{ | ||
uri, | ||
field: 'a', | ||
location: 'Paragraph', | ||
preview: 'Lorem ipsum dolor sit amet…' | ||
}]); | ||
}); | ||
|
||
test('fails if field with invalid link', () => { | ||
expect(fn({ | ||
components: { | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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