diff --git a/lib/SimpleSAML/Utils/Attributes.php b/lib/SimpleSAML/Utils/Attributes.php index 4a138f68299a789615cd991c0e1daacc399f2d4e..00e934f5e192e3332be5078cc7ce493bd8fdef02 100644 --- a/lib/SimpleSAML/Utils/Attributes.php +++ b/lib/SimpleSAML/Utils/Attributes.php @@ -111,24 +111,22 @@ class Attributes /** * Extract an attribute's namespace, or revert to default. * - * This function takes in a namespaced attribute name at splits it in a namespace/attribute name tuple. + * This function takes in a namespaced attribute name and splits it in a namespace/attribute name tuple. * When no namespace is found in the attribute name, it will be namespaced with the default namespace. * This default namespace can be overriden by supplying a second parameter to this function. * * @param string $name The namespaced attribute name. - * @param string $namespace The default namespace that should be used when no namespace is found (optional). + * @param string $defaultns The default namespace that should be used when no namespace is found. * * @return array The attribute name, split to the namespace and the actual attribute name. */ - public static function getAttributeNamespace($name, $namespace = 'http://schemas.xmlsoap.org/claims') + public static function getAttributeNamespace($name, $defaultns) { $slash = strrpos($name, '/'); if ($slash !== false) { - $namespace = substr($name, 0, $slash); + $defaultns = substr($name, 0, $slash); $name = substr($name, $slash + 1); } - $name = htmlspecialchars($name); - $namespace = htmlspecialchars($namespace); - return array($namespace, $name); + return array(htmlspecialchars($defaultns), htmlspecialchars($name)); } } diff --git a/tests/lib/SimpleSAML/Utils/AttributesTest.php b/tests/lib/SimpleSAML/Utils/AttributesTest.php index 41bf895fe76eebbabda7e5f355052e7261dfa5b4..0dc083314e29e18c55ff6d49ef90a60869c93016 100644 --- a/tests/lib/SimpleSAML/Utils/AttributesTest.php +++ b/tests/lib/SimpleSAML/Utils/AttributesTest.php @@ -193,4 +193,23 @@ class AttributesTest extends \PHPUnit_Framework_TestCase 'Attribute array normalization failed' ); } + + + /** + * Test the getAttributeNamespace() function. + */ + public function testNamespacedAttributes() + { + // test for only the name + $this->assertEquals( + array('default', 'name'), + Attributes::getAttributeNamespace('name', 'default') + ); + + // test for a given namespace and multiple '/' + $this->assertEquals( + array('some/namespace', 'name'), + Attributes::getAttributeNamespace('some/namespace/name', 'default') + ); + } }