Skip to content
Snippets Groups Projects
Commit e128a4db authored by Tim van Dijen's avatar Tim van Dijen
Browse files

Move namespace-logic outside of this class for usage elsewhere

parent e6b448a0
No related branches found
No related tags found
No related merge requests found
......@@ -106,4 +106,29 @@ class Attributes
return $newAttrs;
}
/**
* 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.
* 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).
*
* @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')
{
$slash = strrpos($name, '/');
if ($slash !== false) {
$namespace = substr($name, 0, $slash);
$name = substr($name, $slash + 1);
}
$name = htmlspecialchars($name);
$namespace = htmlspecialchars($namespace);
return array($namespace, $name);
}
}
......@@ -61,14 +61,8 @@ MSG;
if ((!is_array($values)) || (count($values) == 0)) {
continue;
}
$namespace = "http://schemas.xmlsoap.org/claims";
$slash = strrpos($name, '/');
if ($slash !== false) {
$namespace = substr($name, 0, $slash);
$name = substr($name, $slash + 1);
}
$name = htmlspecialchars($name);
$namespace = htmlspecialchars($namespace);
list($namespace, $name) = SimpleSAML\Utils\Attributes::getAttributeNamespace($name);
foreach ($values as $value) {
if ((!isset($value)) || ($value === '')) {
continue;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment