Skip to content
This repository has been archived by the owner on Jan 30, 2020. It is now read-only.

Commit

Permalink
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/Ldif/Encoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
} elseif (preg_match('/^([a-z0-9;-]+)(:[:<]?\s*)([^<]*)$/i', $line, $matches)) {
$inComment = false;
$name = strtolower($matches[1]);
$type = trim($matches[2]);
$value = $matches[3];
Expand Down
38 changes: 38 additions & 0 deletions test/Ldif/SimpleDecoderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -370,4 +370,42 @@ public function testRoundtripEncoding()
$expected = array_merge(array('dn' => $node->getDnString()), $node->getData(false));
$this->assertEquals($expected, $data);
}

public function testDecodeSimpleSingleItemWithUri()
{
$data =
"version: 1
dn: cn=test3,ou=example,dc=cno
objectclass: oc1
memberurl: ldap:///(&(cn=myName)(uid=something))";
$expected = array(
'dn' => 'cn=test3,ou=example,dc=cno',
'objectclass' => array('oc1'),
'memberurl' => array('ldap:///(&(cn=myName)(uid=something))'));
$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]);
}
}

0 comments on commit c7c620a

Please sign in to comment.