Skip to content

Commit

Permalink
Fixes #966 - remote @imports referenced from local ones.
Browse files Browse the repository at this point in the history
This is an edge case when local `@import` was given by hash and
referenced a remote one which was processed synchronously but should
have been asynchronously.
  • Loading branch information
jakubpawlowicz committed Sep 2, 2017
1 parent 744bfc5 commit 251ec10
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 4 deletions.
1 change: 1 addition & 0 deletions History.md
Expand Up @@ -4,6 +4,7 @@
* Fixed issue [#959](https://github.com/jakubpawlowicz/clean-css/issues/959) - regression in shortening long hex values.
* Fixed issue [#960](https://github.com/jakubpawlowicz/clean-css/issues/960) - better explanation of `efficiency` stat.
* Fixed issue [#965](https://github.com/jakubpawlowicz/clean-css/issues/965) - edge case in parsing comment endings.
* Fixed issue [#966](https://github.com/jakubpawlowicz/clean-css/issues/966) - remote `@import`s referenced from local ones.

[4.1.7 / 2017-07-14](https://github.com/jakubpawlowicz/clean-css/compare/v4.1.6...v4.1.7)
==================
Expand Down
11 changes: 7 additions & 4 deletions lib/reader/read-sources.js
Expand Up @@ -288,7 +288,6 @@ function inlineLocalStylesheet(uri, mediaQuery, metadata, inlinerContext) {
path.resolve(inlinerContext.rebaseTo, uri);
var relativeToCurrentPath = path.relative(currentPath, absoluteUri);
var importedStyles;
var importedTokens;
var isAllowed = isAllowedResource(uri, false, inlinerContext.inline);
var normalizedPath = normalizePath(relativeToCurrentPath);
var isLoaded = normalizedPath in inlinerContext.externalContext.sourcesContent;
Expand Down Expand Up @@ -316,10 +315,14 @@ function inlineLocalStylesheet(uri, mediaQuery, metadata, inlinerContext) {
inlinerContext.externalContext.sourcesContent[normalizedPath] = importedStyles;
inlinerContext.externalContext.stats.originalSize += importedStyles.length;

importedTokens = fromStyles(importedStyles, inlinerContext.externalContext, inlinerContext, function (tokens) { return tokens; });
importedTokens = wrapInMedia(importedTokens, mediaQuery, metadata);
return fromStyles(importedStyles, inlinerContext.externalContext, inlinerContext, function (importedTokens) {
importedTokens = wrapInMedia(importedTokens, mediaQuery, metadata);

inlinerContext.outputTokens = inlinerContext.outputTokens.concat(importedTokens);
inlinerContext.outputTokens = inlinerContext.outputTokens.concat(importedTokens);
inlinerContext.sourceTokens = inlinerContext.sourceTokens.slice(1);

return doInlineImports(inlinerContext);
});
}

inlinerContext.sourceTokens = inlinerContext.sourceTokens.slice(1);
Expand Down
21 changes: 21 additions & 0 deletions test/protocol-imports-test.js
Expand Up @@ -472,6 +472,27 @@ vows.describe('protocol imports').addBatch({
nock.cleanAll();
}
},
'of a remote resource referenced from local one given via hash': {
topic: function () {
this.reqMocks = nock('http://127.0.0.1')
.get('/remote.css')
.reply(200, 'div{padding:0}');

new CleanCSS({ inline: 'all' }).minify({ 'local.css': { styles: '@import url(http://127.0.0.1/remote.css);' } }, this.callback);
},
'should not raise errors': function (errors, minified) {
assert.isNull(errors);
},
'should process @import': function (errors, minified) {
assert.equal(minified.styles, 'div{padding:0}');
},
'hits the endpoint': function () {
assert.isTrue(this.reqMocks.isDone());
},
teardown: function () {
nock.cleanAll();
}
},
'of a remote resource after content and no callback': {
topic: function () {
var source = '.one{color:red}@import url(http://127.0.0.1/remote.css);';
Expand Down

0 comments on commit 251ec10

Please sign in to comment.