From bec2b0ccd5d21be2549abed315a294b2298eb095 Mon Sep 17 00:00:00 2001 From: kisenka Date: Wed, 28 Feb 2018 17:04:00 +0300 Subject: [PATCH 1/3] feat: skip URLs with tilde --- src/lib/decl-processor.js | 2 +- test/fixtures/skip-urls-with-tilde.css | 3 +++ test/fixtures/skip-urls-with-tilde.expected.css | 3 +++ test/type/copy.js | 5 +++++ test/type/inline.js | 5 +++++ test/type/rebase.js | 4 ++++ 6 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 test/fixtures/skip-urls-with-tilde.css create mode 100644 test/fixtures/skip-urls-with-tilde.expected.css diff --git a/src/lib/decl-processor.js b/src/lib/decl-processor.js index 0a7cbc0..1effa44 100644 --- a/src/lib/decl-processor.js +++ b/src/lib/decl-processor.js @@ -19,7 +19,7 @@ const prepareAsset = paths.prepareAsset; * @type {UrlRegExp[]} */ const URL_PATTERNS = [ - /(url\(\s*['"]?)([^"')]+)(["']?\s*\))/g, + /(url\(\s*['"]?)(?!~)([^"')]+)(["']?\s*\))/g, /(AlphaImageLoader\(\s*src=['"]?)([^"')]+)(["'])/g ]; diff --git a/test/fixtures/skip-urls-with-tilde.css b/test/fixtures/skip-urls-with-tilde.css new file mode 100644 index 0000000..0baa467 --- /dev/null +++ b/test/fixtures/skip-urls-with-tilde.css @@ -0,0 +1,3 @@ +body { + background: url("~one"), url("~./two"), url("~@three"), url("~@four/qwe"); +} diff --git a/test/fixtures/skip-urls-with-tilde.expected.css b/test/fixtures/skip-urls-with-tilde.expected.css new file mode 100644 index 0000000..0baa467 --- /dev/null +++ b/test/fixtures/skip-urls-with-tilde.expected.css @@ -0,0 +1,3 @@ +body { + background: url("~one"), url("~./two"), url("~@three"), url("~@four/qwe"); +} diff --git a/test/type/copy.js b/test/type/copy.js index 353cbff..56caef0 100644 --- a/test/type/copy.js +++ b/test/type/copy.js @@ -1,3 +1,8 @@ +compareFixtures( + 'skip-urls-with-tilde', + 'should skip URLs with tilde' +); + describe('copy without assetsPath', () => { const opts = { url: 'copy' diff --git a/test/type/inline.js b/test/type/inline.js index 1b6019c..3b1dba0 100644 --- a/test/type/inline.js +++ b/test/type/inline.js @@ -24,6 +24,11 @@ describe('inline', () => { postcssOpts ); + compareFixtures( + 'skip-urls-with-tilde', + 'should skip URLs with tilde' + ); + it('should inline url from dirname(from)', () => { const css = processedCss('fixtures/inline-from', opts, postcssOpts); diff --git a/test/type/rebase.js b/test/type/rebase.js index b8d0350..ef80325 100644 --- a/test/type/rebase.js +++ b/test/type/rebase.js @@ -86,4 +86,8 @@ describe('rebase', () => { opts, { from: 'test/fixtures/here', to: 'there' } ); + compareFixtures( + 'skip-urls-with-tilde', + 'should skip URLs with tilde' + ); }); From eeaccb75299d7df3653cabff805d37a3c02bc0c1 Mon Sep 17 00:00:00 2001 From: kisenka Date: Wed, 28 Feb 2018 17:04:23 +0300 Subject: [PATCH 2/3] chore: eslint fix --- src/type/copy.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/type/copy.js b/src/type/copy.js index 48d02d9..2f1da06 100644 --- a/src/type/copy.js +++ b/src/type/copy.js @@ -13,7 +13,7 @@ const getAssetsPath = paths.getAssetsPath; const normalize = paths.normalize; const getHashName = (file, options) => - (options && options.append ? (path.basename(file.path, path.extname(file.path)) + '_') : '') + (options && options.append ? (`${path.basename(file.path, path.extname(file.path))}_`) : '') + calcHash(file.contents, options) + path.extname(file.path); From 00ceb36ee695eec6b38846e90ec8a28b437522d4 Mon Sep 17 00:00:00 2001 From: kisenka Date: Wed, 28 Feb 2018 21:52:42 +0300 Subject: [PATCH 3/3] chore: skip URLs started with tilde --- src/lib/decl-processor.js | 2 +- src/lib/paths.js | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/lib/decl-processor.js b/src/lib/decl-processor.js index 1effa44..0a7cbc0 100644 --- a/src/lib/decl-processor.js +++ b/src/lib/decl-processor.js @@ -19,7 +19,7 @@ const prepareAsset = paths.prepareAsset; * @type {UrlRegExp[]} */ const URL_PATTERNS = [ - /(url\(\s*['"]?)(?!~)([^"')]+)(["']?\s*\))/g, + /(url\(\s*['"]?)([^"')]+)(["']?\s*\))/g, /(AlphaImageLoader\(\s*src=['"]?)([^"')]+)(["'])/g ]; diff --git a/src/lib/paths.js b/src/lib/paths.js index eef8ef8..d7f76c4 100644 --- a/src/lib/paths.js +++ b/src/lib/paths.js @@ -35,7 +35,10 @@ const isUrlWithoutPathname = (assetUrl) => { * @returns {Boolean} */ const isUrlShouldBeIgnored = (assetUrl, options) => { - return isUrlWithoutPathname(assetUrl) || (assetUrl[0] === '/' && !options.basePath); + const isAbsolutePath = assetUrl[0] === '/'; + const isStartsWithTilde = assetUrl[0] === '~'; + + return isUrlWithoutPathname(assetUrl) || ((isAbsolutePath || isStartsWithTilde) && !options.basePath); }; /**