From b0d786c86e5b2c107c05013972127f857bed00f0 Mon Sep 17 00:00:00 2001 From: Roland Gruber Date: Sat, 9 Nov 2019 14:32:35 +0100 Subject: [PATCH] fixed formatting of DN with escaped commas --- lam/lib/account.inc | 4 +++- lam/tests/lib/accountTest.php | 9 +++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/lam/lib/account.inc b/lam/lib/account.inc index b29baf12..25a04091 100644 --- a/lam/lib/account.inc +++ b/lam/lib/account.inc @@ -1053,6 +1053,7 @@ function getAbstractDN($dn) { if ($dn == '') { return ''; } + $dn = str_replace('\\,', '\\2C', $dn); $parts = explode(',', $dn); for ($i = 0; $i < sizeof($parts); $i++) { $subparts = explode('=', $parts[$i]); @@ -1060,7 +1061,8 @@ function getAbstractDN($dn) { $parts[$i] = $subparts[1]; } } - return implode(' > ', $parts); + $abstractDn = implode(' > ', $parts); + return str_replace(array('\\2C', '\\,'), array(',', ','), $abstractDn); } /** diff --git a/lam/tests/lib/accountTest.php b/lam/tests/lib/accountTest.php index 8790ba28..769e9a7d 100644 --- a/lam/tests/lib/accountTest.php +++ b/lam/tests/lib/accountTest.php @@ -135,4 +135,13 @@ class AccountTest extends PHPUnit_Framework_TestCase { $this->assertEquals('cn=test\\2C user,ou=People,o=test,c=de', convertCommaEscaping('cn=test\\, user,ou=People,o=test,c=de')); } + /** + * Tests getAbstractDN(). + */ + function testGetAbstractDN() { + $this->assertEquals('test > test > de', getAbstractDN('cn=test,o=test,c=de')); + $this->assertEquals('test,user > test > de', getAbstractDN('cn=test\\,user,o=test,c=de')); + $this->assertEquals('test,user > test > de', getAbstractDN('cn=test\\2Cuser,o=test,c=de')); + } + }