diff --git a/src/utils/is-url.js b/src/utils/is-url.js index e39f5e5fb73..aea81f9e151 100644 --- a/src/utils/is-url.js +++ b/src/utils/is-url.js @@ -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); }; diff --git a/test/css.js b/test/css.js index c764ab8842a..59dc89b5f59 100644 --- a/test/css.js +++ b/test/css.js @@ -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])); }); diff --git a/test/integration/css-url/index.css b/test/integration/css-url/index.css index b958266cdc3..b657829c0b5 100644 --- a/test/integration/css-url/index.css +++ b/test/integration/css-url/index.css @@ -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); +} diff --git a/test/integration/html/index.html b/test/integration/html/index.html index e5ed02eed31..61d095b8329 100644 --- a/test/integration/html/index.html +++ b/test/integration/html/index.html @@ -7,6 +7,8 @@

Hello world

Linking to another page

Hash link + Mailto link + Tel link