Skip to content

Commit c89f890

Browse files
authored
Merge pull request #502 from saloonphp/fix/parse-url-with-underscores
Fix | URLHelper incorrectly URLs with underscores
2 parents 87bde73 + b30f54c commit c89f890

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

src/Helpers/URLHelper.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@ public static function join(string $baseUrl, string $endpoint): string
4444
*/
4545
public static function isValidUrl(string $url): bool
4646
{
47+
// The following str_replace is used to get around an issue raised by PHP 8.4
48+
// @see https://github.com/php/php-src/issues/17842
49+
50+
$url = str_replace('_', '-', $url);
51+
4752
return ! empty(filter_var($url, FILTER_VALIDATE_URL));
4853
}
4954

tests/Unit/URLHelperTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
['', 'https://google.com/search', 'https://google.com/search'],
1616
['', 'google.com/search', '/google.com/search'],
1717
['https://google.com', 'https://api.google.com/search', 'https://api.google.com/search'],
18+
['', 'https://example_underscores.com/search', 'https://example_underscores.com/search'],
1819
]);
1920

2021
test('the URL helper can parse a variety of query parameters', function (string $query, array $expected) {

0 commit comments

Comments
 (0)