Fixes #203 - passing Buffer instance as a first argument to minify method.
authorGoalSmashers <jakub@goalsmashers.com>
Fri, 3 Jan 2014 11:06:48 +0000 (12:06 +0100)
committerGoalSmashers <jakub@goalsmashers.com>
Fri, 3 Jan 2014 11:20:43 +0000 (12:20 +0100)
History.md
lib/clean.js
test/module-test.js

index 22283cf..1de1838 100644 (file)
@@ -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)
 ==================
index 069f02a..fb17ebd 100644 (file)
@@ -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;
index e50a3b1..b485ae5 100644 (file)
@@ -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);