From 3fa5f7ea6724ecbbfab22cfa98cc5939a7cbf987 Mon Sep 17 00:00:00 2001 From: makoto tsuyuki Date: Mon, 27 Feb 2017 23:15:22 -0800 Subject: [PATCH] fix: spaceless @import cause infinite loop (#136) --- lib/css.js | 4 ++-- test/fixtures/css-import.result.html | 2 +- test/fixtures/css-import.src.html | 2 ++ 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/css.js b/lib/css.js index 0d2166d..28d606f 100644 --- a/lib/css.js +++ b/lib/css.js @@ -56,7 +56,7 @@ function getImports(root, css) { if (position !== -1) { inliner.jobs.add('link', 1); - var match = (css.match(/@import\s*(.*?);/) || [null, ''])[1]; + var match = (css.match(/@import(\s*.*?);/) || [null, ''])[1]; var url = match.replace(/url/, '') .replace(/['}"()]/g, '') .replace(/;/, '') @@ -74,7 +74,7 @@ function getImports(root, css) { importedCSS = '@media ' + url.join(' ') + '{' + importedCSS + '}'; } - css = css.replace('@import ' + match, importedCSS); + css = css.replace('@import' + match, importedCSS); return getImports.call(inliner, root, css); }); } diff --git a/test/fixtures/css-import.result.html b/test/fixtures/css-import.result.html index 2f46cd2..7831350 100644 --- a/test/fixtures/css-import.result.html +++ b/test/fixtures/css-import.result.html @@ -1 +1 @@ - inline style + inline style diff --git a/test/fixtures/css-import.src.html b/test/fixtures/css-import.src.html index 44eab2b..6459e28 100644 --- a/test/fixtures/css-import.src.html +++ b/test/fixtures/css-import.src.html @@ -12,6 +12,8 @@ @import 'import.css'; /* four */ @import url('import.css') screen and (orientation:landscape); + /* five */ + @import"import.css";