Skip to content

Commit

Permalink
fix: spaceless @import cause infinite loop (#136)
Browse files Browse the repository at this point in the history
  • Loading branch information
tsuyukimakoto authored and remy committed Feb 28, 2017
1 parent bacf080 commit 3fa5f7e
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 3 deletions.
4 changes: 2 additions & 2 deletions lib/css.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(/;/, '')
Expand All @@ -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);
});
}
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/css-import.result.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>inline style</title> <style> p{ font-size:10px;background:url("data:image/gif;base64,R0lGODlhAQABAIABAP///wAAACwAAAAAAQABAAACAkQBADs=") repeat;}p:before{ content:'<';color:blue;}; p{ font-size:10px;background:url("data:image/gif;base64,R0lGODlhAQABAIABAP///wAAACwAAAAAAQABAAACAkQBADs=") repeat;}p:before{ content:'<';color:blue;}; p{ font-size:10px;background:url("data:image/gif;base64,R0lGODlhAQABAIABAP///wAAACwAAAAAAQABAAACAkQBADs=") repeat;}p:before{ content:'<';color:blue;}; @media screen and orientation:landscape{p{ font-size:10px;background:url("data:image/gif;base64,R0lGODlhAQABAIABAP///wAAACwAAAAAAQABAAACAkQBADs=") repeat;}p:before{ content:'<';color:blue;}};</style> </head> <body> </body> </html>
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>inline style</title> <style> p{ font-size:10px;background:url("data:image/gif;base64,R0lGODlhAQABAIABAP///wAAACwAAAAAAQABAAACAkQBADs=") repeat;}p:before{ content:'<';color:blue;}; p{ font-size:10px;background:url("data:image/gif;base64,R0lGODlhAQABAIABAP///wAAACwAAAAAAQABAAACAkQBADs=") repeat;}p:before{ content:'<';color:blue;}; p{ font-size:10px;background:url("data:image/gif;base64,R0lGODlhAQABAIABAP///wAAACwAAAAAAQABAAACAkQBADs=") repeat;}p:before{ content:'<';color:blue;}; @media screen and orientation:landscape{p{ font-size:10px;background:url("data:image/gif;base64,R0lGODlhAQABAIABAP///wAAACwAAAAAAQABAAACAkQBADs=") repeat;}p:before{ content:'<';color:blue;}}; p{ font-size:10px;background:url("data:image/gif;base64,R0lGODlhAQABAIABAP///wAAACwAAAAAAQABAAACAkQBADs=") repeat;}p:before{ content:'<';color:blue;};</style> </head> <body> </body> </html>
2 changes: 2 additions & 0 deletions test/fixtures/css-import.src.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
@import 'import.css';
/* four */
@import url('import.css') screen and (orientation:landscape);
/* five */
@import"import.css";
</style>
</head>
<body>
Expand Down

0 comments on commit 3fa5f7e

Please sign in to comment.