diff --git a/lib/ldif.pegjs b/lib/ldif.pegjs index e962090..b8ffb06 100644 --- a/lib/ldif.pegjs +++ b/lib/ldif.pegjs @@ -58,7 +58,7 @@ ldif_content } ldif_entry "entry" - = dn:dn_spec SEP attribs:attrs_spec whitespace* { + = dn:dn_spec SEP attribs:attrs_spec? whitespace* { return new _type.Record(dn,attribs); } diff --git a/lib/parser.js b/lib/parser.js index 7b4dad9..749c458 100644 --- a/lib/parser.js +++ b/lib/parser.js @@ -595,6 +595,9 @@ module.exports = (function() { s2 = peg$parseSEP(); if (s2 !== peg$FAILED) { s3 = peg$parseattrs_spec(); + if (s3 === peg$FAILED) { + s3 = null; + } if (s3 !== peg$FAILED) { s4 = []; s5 = peg$parsewhitespace(); diff --git a/lib/record.js b/lib/record.js index a0946a6..58463c3 100644 --- a/lib/record.js +++ b/lib/record.js @@ -228,6 +228,8 @@ Attribute.prototype = { var Value = function(data){ if (!(this instanceof Value)) return new Value(data); + if (data === null) data = '' + // Automatically convert a string value if (typeof data == 'string') data = { type: 'value', value: data }; diff --git a/test/01_parsing.js b/test/01_parsing.js index 3abb595..ce8469b 100644 --- a/test/01_parsing.js +++ b/test/01_parsing.js @@ -59,6 +59,26 @@ describe('Basic parsing',function(){ done(); }); + it('empty dn',function(done){ + // This is a fix for Issue #5 on github + var parsed = ldif.parse( + 'dn: dc=test\n' + + '\n' + + 'dn: dc=test2\n' + ); + parsed.should.have.property('entries').and.have.length(2); + done(); + }); + + it.only('empty attribute',function(done){ + var parsed = ldif.parse( + 'dn: dc=test\n' + + 'member: \n' + ); + parsed.should.have.property('entries').and.have.length(1); + done(); + }); + }); describe('Records',function(){