From 7974a11845ba8c6b2465ab8e5cb8e93e0a6d7198 Mon Sep 17 00:00:00 2001 From: Tim van Dijen <tvdijen@gmail.com> Date: Sat, 8 Jan 2022 22:00:18 +0100 Subject: [PATCH] print_r() with second param true is guaranteed to return a string --- lib/SimpleSAML/Utils/Attributes.php | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/lib/SimpleSAML/Utils/Attributes.php b/lib/SimpleSAML/Utils/Attributes.php index e778cb12b..af6edfb86 100644 --- a/lib/SimpleSAML/Utils/Attributes.php +++ b/lib/SimpleSAML/Utils/Attributes.php @@ -4,6 +4,7 @@ declare(strict_types=1); namespace SimpleSAML\Utils; +use InvalidArgumentException; use SimpleSAML\Error; /** @@ -35,14 +36,14 @@ class Attributes $attribute = $attributes[$expected]; if (!is_array($attribute)) { - throw new \InvalidArgumentException('The attributes array is not normalized, values should be arrays.'); + throw new InvalidArgumentException('The attributes array is not normalized, values should be arrays.'); } if (count($attribute) === 0) { throw new Error\Exception("Empty attribute '" . $expected . "'.'"); } elseif (count($attribute) > 1) { if ($allow_multiple === false) { - throw new \SimpleSAML\Error\Exception( + throw new Error\Exception( 'More than one value found for the attribute, multiple values not allowed.' ); } @@ -71,7 +72,9 @@ class Attributes $newAttrs = []; foreach ($attributes as $name => $values) { if (!is_string($name)) { - throw new \InvalidArgumentException('Invalid attribute name: "' . print_r($name, true) . '".'); + /** @var string $name */ + $name = print_r($name, true); + throw new InvalidArgumentException(sprintf('Invalid attribute name: "%s".', $name)); } $arrayUtils = new Arrays(); @@ -79,8 +82,10 @@ class Attributes foreach ($values as $value) { if (!is_string($value)) { - throw new \InvalidArgumentException( - 'Invalid attribute value for attribute ' . $name . ': "' . print_r($value, true) . '".' + /** @var string $value */ + $value = print_r($value, true); + throw new InvalidArgumentException( + sprintf('Invalid attribute value for attribute %s: "%s".', $name, $value) ); } } -- GitLab