From a0189f114ac4f8a2594bf8a132cec975aa737f80 Mon Sep 17 00:00:00 2001 From: Pascal Rigaux Date: Tue, 11 Apr 2023 15:07:34 +0200 Subject: [PATCH 1/3] fix #5: handle entries with no attributes --- lib/ldif.pegjs | 2 +- lib/parser.js | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) 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(); From b582647b77fe96365cb28a9d1e62fa1e248d8c88 Mon Sep 17 00:00:00 2001 From: Pascal Rigaux Date: Tue, 20 Jun 2023 10:25:45 +0200 Subject: [PATCH 2/3] add test for issue #5 --- test/01_parsing.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/test/01_parsing.js b/test/01_parsing.js index 3abb595..f01517b 100644 --- a/test/01_parsing.js +++ b/test/01_parsing.js @@ -59,6 +59,17 @@ 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(); + }); + }); describe('Records',function(){ From 09170c76d4ff083436f2c6e941e547f285248ec8 Mon Sep 17 00:00:00 2001 From: Pascal Rigaux Date: Tue, 20 Jun 2023 10:26:28 +0200 Subject: [PATCH 3/3] fix #15: handle empty attribute value --- lib/record.js | 2 ++ test/01_parsing.js | 9 +++++++++ 2 files changed, 11 insertions(+) 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 f01517b..ce8469b 100644 --- a/test/01_parsing.js +++ b/test/01_parsing.js @@ -70,6 +70,15 @@ describe('Basic parsing',function(){ 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(){