From baa72ea085ecf0a5925b3cdd300a5ea744b5ebe2 Mon Sep 17 00:00:00 2001 From: Arpad Borsos Date: Tue, 28 Jul 2015 10:09:27 +0200 Subject: [PATCH 1/3] fix inlining function trying to read file with querystring --- index.js | 8 ++++---- test/fixtures/copy-parameters.css | 2 +- test/index.js | 3 ++- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/index.js b/index.js index 5394ac9..64abd1a 100755 --- a/index.js +++ b/index.js @@ -227,12 +227,12 @@ function processInline(result, from, dirname, urlMeta, to, options, decl) { } if (basePath) { - fullFilePath = path.join(basePath, urlMeta.value) + fullFilePath = path.join(basePath, link.pathname) } else { fullFilePath = dirname !== from - ? dirname + path.sep + urlMeta.value - : urlMeta.value + ? dirname + path.sep + link.pathname + : link.pathname } var file = path.resolve(from, fullFilePath) @@ -282,7 +282,7 @@ function processInline(result, from, dirname, urlMeta, to, options, decl) { */ function processCopy(result, from, dirname, urlMeta, to, options, decl) { if (from === to) { - result.warn("Option `to` of postscss is required, ignoring", {node: decl}) + result.warn("Option `to` of postcss is required, ignoring", {node: decl}) return createUrl(urlMeta) } var relativeAssetsPath = (options && options.assetsPath) diff --git a/test/fixtures/copy-parameters.css b/test/fixtures/copy-parameters.css index 44c4844..3a60367 100644 --- a/test/fixtures/copy-parameters.css +++ b/test/fixtures/copy-parameters.css @@ -1,5 +1,5 @@ body { - clip-path: url("imported/pixel.png?#iefix") + clip-path: url("imported/pixel.png?foo=bar") } div { diff --git a/test/index.js b/test/index.js index 3fafdbd..3db81e4 100755 --- a/test/index.js +++ b/test/index.js @@ -169,7 +169,7 @@ function testCopy(t, opts, postcssOpts) { copyPixelGif: new RegExp("\"" + assetsPath + "pixel\\.gif\""), copyParamsPixelPng: - new RegExp("\"" + assetsPath + "imported\/pixel\\.png\\?\#iefix\""), + new RegExp("\"" + assetsPath + "imported\/pixel\\.png\\?foo=bar\""), copyParamsPixelGif: new RegExp("\"" + assetsPath + "pixel\\.gif\\#el\""), copyHashPixel: @@ -270,6 +270,7 @@ test("copy-when-inline-fallback", function(t) { url: "inline", maxSize: 0, fallback: "copy", + assetsPath: "assets", } compareFixtures( From cc960396424bbe640b29cbd76d6bb4aec7870cda Mon Sep 17 00:00:00 2001 From: Arpad Borsos Date: Tue, 28 Jul 2015 10:30:22 +0200 Subject: [PATCH 2/3] fix filename hashing function getting confused by querystrings with dots in them --- index.js | 8 +++++--- test/fixtures/copy-hash-parameters.css | 2 +- test/index.js | 2 +- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/index.js b/index.js index 64abd1a..5c2c894 100755 --- a/index.js +++ b/index.js @@ -241,13 +241,14 @@ function processInline(result, from, dirname, urlMeta, to, options, decl) { return createUrl(urlMeta) } - var mimeType = mime.lookup(file) var stats = fs.statSync(file) if (stats.size >= maxSize) { return processFallback() } + var mimeType = mime.lookup(file) + if (!mimeType) { result.warn("Unable to find asset mime-type for " + file, {node: decl}) return createUrl(urlMeta) @@ -295,7 +296,8 @@ function processCopy(result, from, dirname, urlMeta, to, options, decl) { // remove hash or parameters in the url. // e.g., url('glyphicons-halflings-regular.eot?#iefix') - var filePath = url.parse(filePathUrl, true).pathname + var fileLink = url.parse(filePathUrl, true) + var filePath = fileLink.pathname var name = path.basename(filePath) var useHash = options.useHash || false @@ -319,8 +321,8 @@ function processCopy(result, from, dirname, urlMeta, to, options, decl) { .update(contents) .digest("hex") .substr(0, 16) - nameUrl = name + path.extname(filePathUrl) name += path.extname(filePath) + nameUrl = name + (fileLink.search || "") + (fileLink.hash || "") } else { if (!pathIsAbsolute.posix(from)) { diff --git a/test/fixtures/copy-hash-parameters.css b/test/fixtures/copy-hash-parameters.css index 552e1cb..2b082e6 100644 --- a/test/fixtures/copy-hash-parameters.css +++ b/test/fixtures/copy-hash-parameters.css @@ -1,3 +1,3 @@ body { - clip-path: url("imported/pixel.png?#iefix") + clip-path: url("imported/pixel.png?v=1.1#iefix") } diff --git a/test/index.js b/test/index.js index 3db81e4..357c285 100755 --- a/test/index.js +++ b/test/index.js @@ -175,7 +175,7 @@ function testCopy(t, opts, postcssOpts) { copyHashPixel: new RegExp("\"" + assetsPath + "[a-z0-9]{16}\\.png\""), copyHashParamsPixel: - new RegExp("\"" + assetsPath + "[a-z0-9]{16}\\.png\\?\\#iefix\""), + new RegExp("\"" + assetsPath + "[a-z0-9]{16}\\.png\\?v=1\\.1\\#iefix\""), } var css = postcss() From f7e70a10a69a5f6cb2656a89ec8aa9f228a9ea11 Mon Sep 17 00:00:00 2001 From: Arpad Borsos Date: Tue, 28 Jul 2015 12:39:52 +0200 Subject: [PATCH 3/3] fix review nit: keep old testcase --- test/fixtures/copy-parameters.css | 4 ++++ test/index.js | 7 +++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/test/fixtures/copy-parameters.css b/test/fixtures/copy-parameters.css index 3a60367..a523b4e 100644 --- a/test/fixtures/copy-parameters.css +++ b/test/fixtures/copy-parameters.css @@ -1,4 +1,8 @@ body { + clip-path: url("imported/pixel.png?#iefix") +} + +header { clip-path: url("imported/pixel.png?foo=bar") } diff --git a/test/index.js b/test/index.js index 357c285..122f9a4 100755 --- a/test/index.js +++ b/test/index.js @@ -168,7 +168,9 @@ function testCopy(t, opts, postcssOpts) { new RegExp("\"" + assetsPath + "imported\/pixel\.png\""), copyPixelGif: new RegExp("\"" + assetsPath + "pixel\\.gif\""), - copyParamsPixelPng: + copyParamsPixelPngHash: + new RegExp("\"" + assetsPath + "imported\/pixel\\.png\\?\#iefix\""), + copyParamsPixelPngParam: new RegExp("\"" + assetsPath + "imported\/pixel\\.png\\?foo=bar\""), copyParamsPixelGif: new RegExp("\"" + assetsPath + "pixel\\.gif\\#el\""), @@ -199,7 +201,8 @@ function testCopy(t, opts, postcssOpts) { t.ok( ( - css.match(patterns.copyParamsPixelPng) && + css.match(patterns.copyParamsPixelPngHash) && + css.match(patterns.copyParamsPixelPngParam) && css.match(patterns.copyParamsPixelGif) ), "should copy asset from the source (`from`) to the assets destination " +