splitRDNMultivalue() public static method

A RDN can contain multiple values, spearated by a plus sign. This method returns each separate ocl=value pair of the RDN part. If no multivalued RDN is detected, an array containing only the original RDN part is returned. For example, the multivalued RDN 'OU=Sales+CN=J. Smith' is exploded to: array([0] => 'OU=Sales', [1] => 'CN=J. Smith') The method tries to be smart if it encounters unescaped "+" characters, but may fail, so better ensure escaped "+" in attribute names and values. [BUG] If you have a multivalued RDN with unescaped plus characters and there is a unescaped plus sign at the end of an value followed by an attribute name containing an unescaped plus, then you will get wrong splitting: $rdn = 'OU=Sales+C+N=J. Smith'; returns: array('OU=Sales+C', 'N=J. Smith'); The "C+" is treaten as the value of the first pair instead of as the attribute name of the second pair. To prevent this, escape correctly.
public static splitRDNMultivalue ( string $rdn ) : array
$rdn string Part of a (multivalued) escaped RDN (e.g. ou=foo or ou=foo+cn=bar)
return array The components of the multivalued RDN.
Beispiel #1
0
 /**
  * Tests splitRDNMultivalue()
  *
  * In addition to the above test of the basic split correction, we test
  * here the functionality of multivalued RDNs.
  */
 public function testSplitRDNMultivalue()
 {
     // One value.
     $rdn = 'CN=J. Smith';
     $expected = array('CN=J. Smith');
     $split = Horde_Ldap_Util::splitRDNMultivalue($rdn);
     $this->assertEquals($expected, $split);
     // Two values.
     $rdn = 'OU=Sales+CN=J. Smith';
     $expected = array('OU=Sales', 'CN=J. Smith');
     $split = Horde_Ldap_Util::splitRDNMultivalue($rdn);
     $this->assertEquals($expected, $split);
     // Several multivals.
     $rdn = 'OU=Sales+CN=J. Smith+L=London+C=England';
     $expected = array('OU=Sales', 'CN=J. Smith', 'L=London', 'C=England');
     $split = Horde_Ldap_Util::splitRDNMultivalue($rdn);
     $this->assertEquals($expected, $split);
     // Unescaped "+" in value.
     $rdn = 'OU=Sa+les+CN=J. Smith';
     $expected = array('OU=Sa+les', 'CN=J. Smith');
     $split = Horde_Ldap_Util::splitRDNMultivalue($rdn);
     $this->assertEquals($expected, $split);
     // Unescaped "+" in attr name.
     $rdn = 'O+U=Sales+CN=J. Smith';
     $expected = array('O+U=Sales', 'CN=J. Smith');
     $split = Horde_Ldap_Util::splitRDNMultivalue($rdn);
     $this->assertEquals($expected, $split);
     // Unescaped "+" in attr name + value.
     $rdn = 'O+U=Sales+CN=J. Sm+ith';
     $expected = array('O+U=Sales', 'CN=J. Sm+ith');
     $split = Horde_Ldap_Util::splitRDNMultivalue($rdn);
     $this->assertEquals($expected, $split);
     // Unescaped "+" in attribute name, but not first attribute.  This
     // documents a known bug. However, unfortunately we can't know wether
     // the "C+" belongs to value "Sales" or attribute "C+N".  To solve
     // this, we must ask the schema which we do not right now.  The problem
     // is located in _correct_dn_splitting().
     $rdn = 'OU=Sales+C+N=J. Smith';
     // The "C+" is treaten as value of "OU".
     $expected = array('OU=Sales+C', 'N=J. Smith');
     $split = Horde_Ldap_Util::splitRDNMultivalue($rdn);
     $this->assertEquals($expected, $split);
     // Escaped "+" in attribute name and value.
     $rdn = 'O\\+U=Sales+CN=J. Sm\\+ith';
     $expected = array('O\\+U=Sales', 'CN=J. Sm\\+ith');
     $split = Horde_Ldap_Util::splitRDNMultivalue($rdn);
     $this->assertEquals($expected, $split);
 }