From: GoalSmashers Date: Fri, 3 Jan 2014 11:06:48 +0000 (+0100) Subject: Fixes #203 - passing Buffer instance as a first argument to minify method. X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=0dbb54a3a8cea4c3c69090f651d23745b3eb071f;p=clean-css.git Fixes #203 - passing Buffer instance as a first argument to minify method. --- diff --git a/History.md b/History.md index 22283cf5..1de1838e 100644 --- a/History.md +++ b/History.md @@ -13,6 +13,7 @@ ================== * Fixed issue [#199](https://github.com/GoalSmashers/clean-css/issues/199) - keep line breaks with no advanced optimizations. +* Fixed issue [#203](https://github.com/GoalSmashers/clean-css/issues/203) - Buffer as a first argument to minify method. [2.0.4 / 2013-12-19](https://github.com/GoalSmashers/clean-css/compare/v2.0.3...v2.0.4) ================== diff --git a/lib/clean.js b/lib/clean.js index 069f02a9..fb17ebdd 100644 --- a/lib/clean.js +++ b/lib/clean.js @@ -58,6 +58,9 @@ CleanCSS.prototype.minify = function(data) { var context = this.context; var lineBreak = this.lineBreak; + if (Buffer.isBuffer(data)) + data = data.toString(); + if (options.debug) { startedAt = process.hrtime(); stats.originalSize = data.length; diff --git a/test/module-test.js b/test/module-test.js index e50a3b18..b485ae56 100644 --- a/test/module-test.js +++ b/test/module-test.js @@ -148,5 +148,13 @@ vows.describe('module tests').addBatch({ assert.equal(minifier.errors.length, 1); assert.equal(minifier.errors[0], 'Broken @import declaration of "/some/fake/file"'); } + }, + 'buffer passed in': { + 'topic': function() { + return new CleanCSS().minify(new Buffer('@import url(test/data/partials/one.css);')); + }, + 'should be processed correctly': function(minified) { + assert.equal('.one{color:red}', minified); + } } }).export(module);