Skip to content
Open
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
10 changes: 7 additions & 3 deletions lib/shellVarParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,13 @@ var shellVarParser = {
var lines = content.split('\n');

_(lines).each(function(line){
var keyValueArray = line.split('=');
var key = keyValueArray[0].trim();
var value = keyValueArray[1].trim();
var splitIdx = line.indexOf('=');
// handle a line without '='
if (splitIdx < 0) {
splitIdx = line.length;
}
var key = line.substr(0, splitIdx).trim();
var value = line.substr(splitIdx + 1).trim();

// handle quotes for strings
if (value.charAt(0) === '"' && value.charAt(value.length-1) == '"') {
Expand Down
12 changes: 12 additions & 0 deletions test/shellVarParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,17 @@ describe('shellVarParser', function() {
it('does not expand newlines if single-quoted', function() {
parsed("DONT_EXPAND_NEWLINES_SINGLE_QUOTED='dontexpand\\nnewlines'").DONT_EXPAND_NEWLINES_SINGLE_QUOTED.should.eql("dontexpand\\nnewlines");
});

it('allows equals in the value', function() {
parsed("EQUALS_IN_VALUE=this!=that,me == myself").EQUALS_IN_VALUE.should.equal("this!=that,me == myself");
});

it('does not break on a key with blank value', function() {
parsed("BLANK_VALUE=").BLANK_VALUE.should.eql("");
});

it('does not break on a key with missing value', function() {
parsed("NO_VALUE").NO_VALUE.should.eql("");
});
});
});