From eaf5bf622c38be28d0092dc3e99194ac6c106554 Mon Sep 17 00:00:00 2001 From: Maxime Douailin Date: Tue, 30 Apr 2013 22:08:01 +0200 Subject: [PATCH] =?UTF-8?q?[Ldap][Encoder]=C2=A0Fix=20multiline=20comments?= =?UTF-8?q?=20bug=20with=20base64=20attributes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Ldif/Encoder.php | 5 ++++- test/Ldif/SimpleDecoderTest.php | 23 +++++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/src/Ldif/Encoder.php b/src/Ldif/Encoder.php index a43afd4b9..ea08fb35d 100644 --- a/src/Ldif/Encoder.php +++ b/src/Ldif/Encoder.php @@ -65,14 +65,17 @@ protected function _decode($string) $items = array(); $item = array(); $last = null; + $inComment = false; foreach (explode("\n", $string) as $line) { $line = rtrim($line, "\x09\x0A\x0D\x00\x0B"); $matches = array(); - if (substr($line, 0, 1) === ' ' && $last !== null) { + if (substr($line, 0, 1) === ' ' && $last !== null && !$inComment) { $last[2] .= substr($line, 1); } elseif (substr($line, 0, 1) === '#') { + $inComment = true; continue; } elseif (preg_match('/^([a-z0-9;-]+)(:[:<]?\s*)([^<]*)$/i', $line, $matches)) { + $inComment = false; $name = strtolower($matches[1]); $type = trim($matches[2]); $value = $matches[3]; diff --git a/test/Ldif/SimpleDecoderTest.php b/test/Ldif/SimpleDecoderTest.php index 68d2961b8..fd1624b76 100644 --- a/test/Ldif/SimpleDecoderTest.php +++ b/test/Ldif/SimpleDecoderTest.php @@ -385,4 +385,27 @@ public function testDecodeSimpleSingleItemWithUri() $actual = Ldif\Encoder::decode($data); $this->assertEquals($expected, $actual); } + + + public function testDecodeSimpleSingleItemWithMultilineComment() + { + $data = +"version: 1 +dn: cn=test3,ou=example,dc=cno +objectclass: oc1 +attr3:: w7bDpMO8 + +# This is a comment + on multiple lines +dn: cn=test4,ou=example,dc=cno +objectclass: oc1 +attr3:: w7bDpMO8"; + + $expected = array( + 'dn' => 'cn=test3,ou=example,dc=cno', + 'objectclass' => array('oc1'), + 'attr3' => array('öäü')); + $actual = Ldif\Encoder::decode($data); + $this->assertEquals($expected, $actual[0]); + } }