Skip to content

Commit

Permalink
skip processing invalid lines (#6)
Browse files Browse the repository at this point in the history
* skip processing invalid lines

* noop: lint WS updates

* version bump & changes update

* add regex coverage

* add ini file with garbage
  • Loading branch information
msimerson committed Nov 11, 2016
1 parent 051fa1c commit 9cdf696
Show file tree
Hide file tree
Showing 6 changed files with 97 additions and 10 deletions.
4 changes: 4 additions & 0 deletions Changes.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@

# 1.0.6 - 2016-11-10

* handle invalid .ini lines properly (skip them)

# 1.0.5 - 2016-10-25

* do not leave behind a `*` section in config (due to wildcard boolean)
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"name": "haraka-config",
"license": "MIT",
"description": "Haraka's config file loader",
"version": "1.0.5",
"version": "1.0.6",
"homepage": "http://haraka.github.io",
"repository": {
"type": "git",
Expand Down
4 changes: 2 additions & 2 deletions readers/ini.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ exports.load = function (name, options, regex) {
result = this.init_booleans(options, result);

var match;
var is_array_match;
var setter;
var pre = '';

Expand Down Expand Up @@ -45,9 +44,10 @@ exports.load = function (name, options, regex) {
if (!match) {
exports.logger(
'Invalid line in config file \'' + name + '\': ' + line);
return;
}

is_array_match = regex.is_array.exec(match[1]);
var is_array_match = regex.is_array.exec(match[1]);
if (is_array_match) {
setter = function(key, value) {
key = key.replace('[]', '');
Expand Down
1 change: 1 addition & 0 deletions test/config/goobers.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SHA:HIGH:!aNULL:!eNULL:!EXPORT:!DES:!MD5:!PSK:!RC4
77 changes: 75 additions & 2 deletions test/configfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,10 @@ exports.load_config = {
'test.ini, sect1, opts, w/defaults' : function (test) {
test.expect(6);
var r = this.cfreader.load_config('test/config/test.ini', 'ini', {
booleans: ['+sect1.bool_true','-sect1.bool_false',
'+sect1.bool_true_default', 'sect1.-bool_false_default']
booleans: [
'+sect1.bool_true','-sect1.bool_false',
'+sect1.bool_true_default', 'sect1.-bool_false_default'
]
});
test.strictEqual(r.sect1.bool_true, true);
test.strictEqual(r.sect1.bool_false, false);
Expand Down Expand Up @@ -299,3 +301,74 @@ exports.get_cache_key = {
test.done();
}
};

exports.regex = {
setUp: _set_up,
'section': function (test) {
test.expect(4);
test.equal(this.cfreader.regex.section.test('[foo]'), true);
test.equal(this.cfreader.regex.section.test('bar'), false);
test.equal(this.cfreader.regex.section.test('[bar'), false);
test.equal(this.cfreader.regex.section.test('bar]'), false);
test.done();
},
'param': function (test) {
test.expect(2);
test.equal(this.cfreader.regex.param.exec('foo=true')[1], 'foo');
test.equal(this.cfreader.regex.param.exec(';foo=true'), undefined);
test.done();
},
'comment': function (test) {
test.expect(2);
test.equal(this.cfreader.regex.comment.test('; true'), true);
test.equal(this.cfreader.regex.comment.test('false'), false);
test.done();
},
'line': function (test) {
test.expect(2);
test.equal(this.cfreader.regex.line.test(' boo '), true);
test.equal(this.cfreader.regex.line.test('foo'), true);
test.done();
},
'blank': function (test) {
test.expect(2);
test.equal(this.cfreader.regex.blank.test('foo'), false);
test.equal(this.cfreader.regex.blank.test(' '), true);
test.done();
},
// 'continuation': function (test) {
// test.expect(1);
// test.done();
// },
'is_integer': function (test) {
test.expect(3);
test.equal(this.cfreader.regex.is_integer.test(1), true);
test.equal(this.cfreader.regex.is_integer.test(''), false);
test.equal(this.cfreader.regex.is_integer.test('a'), false);
test.done();
},
'is_float': function (test) {
test.expect(3);
test.equal(this.cfreader.regex.is_float.test('1.0'), true);
test.equal(this.cfreader.regex.is_float.test(''), false);
test.equal(this.cfreader.regex.is_float.test('45'), false);
test.done();
},
'is_truth': function (test) {
test.expect(6);
test.equal(this.cfreader.regex.is_truth.test('no'), false);
test.equal(this.cfreader.regex.is_truth.test('nope'), false);
test.equal(this.cfreader.regex.is_truth.test('nuh uh'), false);
test.equal(this.cfreader.regex.is_truth.test('yes'), true);
test.equal(this.cfreader.regex.is_truth.test('true'), true);
test.equal(this.cfreader.regex.is_truth.test(true), true);
test.done();
},
'is_array': function (test) {
test.expect(3);
test.equal(this.cfreader.regex.is_array.test('foo=bar'), false);
test.equal(this.cfreader.regex.is_array.test('foo'), false);
test.equal(this.cfreader.regex.is_array.test('foo[]'), true);
test.done();
},
}
19 changes: 14 additions & 5 deletions test/readers/ini.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,10 @@ exports.load = {
test.expect(1);
var result = this.ini.load('test/config/test.ini', {}, regex);
// console.log(result);
test.deepEqual(result.main,
{ bool_true: 'true', bool_false: 'false',
str_true: 'true', str_false: 'false'
}
);
test.deepEqual(result.main, {
bool_true: 'true', bool_false: 'false',
str_true: 'true', str_false: 'false'
});
test.done();
},
'test.ini, no opts' : function (test) {
Expand Down Expand Up @@ -154,3 +153,13 @@ exports.empty = {
test.done();
},
};

exports.invalid = {
setUp: _set_up,
'goobers.ini has invalid entry' : function (test) {
test.expect(1);
var result = this.ini.load('test/config/goobers.ini', {}, regex);
test.deepEqual(result, { main: { } } );
test.done();
},
}

0 comments on commit 9cdf696

Please sign in to comment.