-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Do not try to import data: tel: mailto: something: URLs (#50)
* Ignore data URLs * Add tests * Ignore tel and mailto URLs * Hoist regexes into constants
- Loading branch information
1 parent
bb75349
commit 781b7ec
Showing
4 changed files
with
21 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,11 @@ | ||
const isURL = require('is-url'); | ||
|
||
// Matches anchor (ie: #raptors) | ||
const ANCHOR_REGEXP = /^#/; | ||
|
||
// Matches scheme (ie: tel:, mailto:, data:) | ||
const SCHEME_REGEXP = /^[a-z]*\:/i; | ||
|
||
module.exports = function (url) { | ||
return isURL(url) || /^#/.test(url); | ||
return isURL(url) || ANCHOR_REGEXP.test(url) || SCHEME_REGEXP.test(url); | ||
}; |
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 |
---|---|---|
|
@@ -7,6 +7,8 @@ | |
<h1>Hello world</h1> | ||
<p>Linking to <a href="other.html">another page</a></p> | ||
<a href="#hash_link">Hash link</a> | ||
<a href="mailto:[email protected]">Mailto link</a> | ||
<a href="tel:+33636757575">Tel link</a> | ||
<script src="index.js"></script> | ||
<script src="https://unpkg.com/parcel-bundler"></script> | ||
</body> | ||
|