Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not try to import data: tel: mailto: something: URLs #50

Merged
merged 4 commits into from
Dec 6, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/utils/is-url.js
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);
};
4 changes: 4 additions & 0 deletions test/css.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ describe('css', function () {
assert(/url\("[0-9a-f]+\.woff2"\)/.test(css));
assert(css.includes('url("http://google.com")'));
assert(css.includes('.index'));
assert(css.includes('url("data:image/gif;base64,quotes")'));
assert(css.includes('.quotes'));
assert(css.includes('url(data:image/gif;base64,no-quote)'));
assert(css.includes('.no-quote'));

assert(fs.existsSync(__dirname + '/dist/' + css.match(/url\("([0-9a-f]+\.woff2)"\)/)[1]));
});
Expand Down
8 changes: 8 additions & 0 deletions test/integration/css-url/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,11 @@
.index {
background: url("http://google.com");
}

.quotes {
background: url("data:image/gif;base64,quotes");
}

.no-quote {
background: url(data:image/gif;base64,no-quote);
}
2 changes: 2 additions & 0 deletions test/integration/html/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -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:someone@acme.com">Mailto link</a>
<a href="tel:+33636757575">Tel link</a>
<script src="index.js"></script>
<script src="https://unpkg.com/parcel-bundler"></script>
</body>
Expand Down