Skip to content

Commit

Permalink
fix: ensure we cast to string when calling rawurlencode()
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
weierophinney committed Nov 19, 2020
1 parent 5048f28 commit e5c1be4
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Http/Regex.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
6 changes: 6 additions & 0 deletions test/Http/RegexTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ public static function routeProvider()
null,
['bar' => 'bar', 'baz' => 'baz']
],
'params-contain-non-string-scalar-values' => [
new Regex('/id/(?<id>\d+)/scale/(?<scale>\d+\.\d+)', '/id/%id%/scale/%scale%'),
'/id/42/scale/4.2',
null,
['id' => 42, 'scale' => 4.2]
],
];
}

Expand Down

0 comments on commit e5c1be4

Please sign in to comment.