From 30509e2bc3c42a0592495d7448dc80d0868ef56c Mon Sep 17 00:00:00 2001 From: Matthew Weier O'Phinney Date: Thu, 19 Nov 2020 12:12:46 -0600 Subject: [PATCH] fix: ensure we cast to string when calling `rawurlencode()` The `Regex` router, when assembling a URL, was not casting values to string when calling `rawurlencode()`, leading to a `TypeError` in PHP 8. [optional footerFixes #14 Signed-off-by: Matthew Weier O'Phinney --- src/Http/Regex.php | 2 +- test/Http/RegexTest.php | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/Http/Regex.php b/src/Http/Regex.php index c99502bc..4d5cf79b 100644 --- a/src/Http/Regex.php +++ b/src/Http/Regex.php @@ -155,7 +155,7 @@ public function assemble(array $params = [], array $options = []) $spec = '%' . $key . '%'; if (strpos($url, $spec) !== false) { - $url = str_replace($spec, rawurlencode($value), $url); + $url = str_replace($spec, rawurlencode((string) $value), $url); $this->assembledParams[] = $key; } diff --git a/test/Http/RegexTest.php b/test/Http/RegexTest.php index 3bc6daa1..360196b3 100644 --- a/test/Http/RegexTest.php +++ b/test/Http/RegexTest.php @@ -64,6 +64,12 @@ public static function routeProvider() null, ['bar' => 'bar', 'baz' => 'baz'] ], + 'params-contain-non-string-scalar-values' => [ + new Regex('/id/(?\d+)/scale/(?\d+\.\d+)', '/id/%id%/scale/%scale%'), + '/id/42/scale/4.2', + null, + ['id' => 42, 'scale' => 4.2] + ], ]; }