/** * Retrieve this leaf-filters attribute, match and value component. * * For leaf filters, this returns array(attr, match, value). * Match is be the logical operator, not the text representation, * eg "=" instead of "equals". Note that some operators are really * a combination of operator+value with wildcard, like * "begins": That will return "=" with the value "value*"! * * For non-leaf filters this will drop an error. * * @todo $this->_match is not always available and thus not usable here; it would be great if it would set in the factory methods and constructor. * @return array|Net_LDAP2_Error */ function getComponents() { if ($this->isLeaf()) { $raw_filter = preg_replace('/^\\(|\\)$/', '', $this->_filter); $parts = Net_LDAP2_Util::split_attribute_string($raw_filter, true, true); if (count($parts) != 3) { return PEAR::raiseError("Net_LDAP2_Filter getComponents() error: invalid filter syntax - unknown matching rule used"); } else { return $parts; } } else { return PEAR::raiseError('Net_LDAP2_Filter getComponents() call is invalid for non-leaf filters!'); } }
/** * Test if split_attribute_string() works */ public function testSplitAttributeString() { // test default behavour $this->assertEquals(array('fooAttr', 'barValue'), Net_LDAP2_Util::split_attribute_string("fooAttr=barValue")); $this->assertEquals(array('fooAttr', '=barValue'), Net_LDAP2_Util::split_attribute_string("fooAttr==barValue")); $this->assertEquals(array('fooAttr', 'bar=Value'), Net_LDAP2_Util::split_attribute_string("fooAttr=bar=Value")); $this->assertEquals(array('foo\\=Attr', 'barValue'), Net_LDAP2_Util::split_attribute_string("foo\\=Attr=barValue")); $this->assertEquals(array('fooAttr', 'bar\\=Value'), Net_LDAP2_Util::split_attribute_string("fooAttr=bar\\=Value")); // test default behaviour with delim $this->assertEquals(array('fooAttr', '=', 'barValue'), Net_LDAP2_Util::split_attribute_string("fooAttr=barValue", false, true)); $this->assertEquals(array('fooAttr', '=', '=barValue'), Net_LDAP2_Util::split_attribute_string("fooAttr==barValue", false, true)); $this->assertEquals(array('fooAttr', '=', 'bar=Value'), Net_LDAP2_Util::split_attribute_string("fooAttr=bar=Value", false, true)); $this->assertEquals(array('foo\\=Attr', '=', 'barValue'), Net_LDAP2_Util::split_attribute_string("foo\\=Attr=barValue", false, true)); // test basic extended splitting and delimter return $test_delimeters = array('=', '~=', '>', '>=', '<', '<='); foreach ($test_delimeters as $td) { // default behavior with simple parameters $this->assertEquals(array('fooAttr', 'barValue'), Net_LDAP2_Util::split_attribute_string("fooAttr{$td}barValue", true), "AttrString='fooAttr{$td}barValue'; sep='{$td}'"); $this->assertEquals(array('fooAttr', 'barValue'), Net_LDAP2_Util::split_attribute_string("fooAttr{$td}barValue", true, false)); // test proper escaping $tde = addcslashes($td, '=~><'); $this->assertEquals(array("foo{$tde}Attr", 'barValue'), Net_LDAP2_Util::split_attribute_string("foo{$tde}Attr{$td}barValue", true)); } // negative test case: perform no split $this->assertEquals(array('fooAttr barValue'), Net_LDAP2_Util::split_attribute_string('fooAttr barValue')); $this->assertEquals(array('fooAttr barValue'), Net_LDAP2_Util::split_attribute_string('fooAttr barValue', true, true)); $this->assertEquals(array('fooAttr>barValue'), Net_LDAP2_Util::split_attribute_string('fooAttr>barValue')); // extended splitting used, but not activated // negative testcase: wrong escaping used $this->assertEquals(array('fooAttr\\>', 'barValue'), Net_LDAP2_Util::split_attribute_string('fooAttr\\>=barValue', false, false)); $this->assertEquals(array('fooAttr\\>', '=', 'barValue'), Net_LDAP2_Util::split_attribute_string('fooAttr\\>=barValue', true, true)); $this->assertEquals(array('fooAttr', '>', '\\=barValue'), Net_LDAP2_Util::split_attribute_string('fooAttr>\\=barValue', true, true)); $this->assertEquals(array('fooAttr\\>\\=barValue'), Net_LDAP2_Util::split_attribute_string('fooAttr\\>\\=barValue', true, true)); }