Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix KSS parser failing on empty file #467

Merged
merged 1 commit into from
Feb 11, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion lib/modules/kss-parser.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

'use strict';
var kss = require('kss'),
path = require('path'),
Expand Down Expand Up @@ -94,6 +93,10 @@ function processBlock(block, options) {
}

function processFile(contents, filePath, syntax, options) {
if (!contents || contents.length === 0) {
return Q.resolve([]);
}

return Q.Promise(function(resolve, reject) {
var blockPromises = [],
blocks;
Expand Down
21 changes: 21 additions & 0 deletions test/unit/modules/kss-parser.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,27 @@ describe('KSS parser', function() {
};
}

it('does not crash on empty .less file', function(done) {
var files = { 'file1.less': '' };
parse(files).then(function(sections) {
expect(sections.length).to.eql(0);
}).then(done).catch(done);
});

it('does not crash on empty .sass file', function(done) {
var files = { 'file1.sass': '' };
parse(files).then(function(sections) {
expect(sections.length).to.eql(0);
}).then(done).catch(done);
});

it('does not crash on empty .scss file', function(done) {
var files = { 'file1.scss': '' };
parse(files).then(function(sections) {
expect(sections.length).to.eql(0);
}).then(done).catch(done);
});

it('parses sections from multiple files', function(done) {
var files = {
'file1.less': multiline(function() {
Expand Down