diff --git a/CHANGELOG.md b/CHANGELOG.md index 23ffa60..c1bd9cf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [2.1.1] - 2024-01-31 +### Fixed +- An issue in the Validator, when trying to validate an absolute input URL that contains non ASCII characters. + ## [2.1.0] - 2023-10-21 ### Added - Method `toPsr7()` to conveniently get a PSR-7 compatible instance from an `Url` instance. Basically wrapper for `new Uri($urlInstance)`. diff --git a/LICENSE b/LICENSE index 152e00c..81fc620 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,4 @@ -Copyright (c) 2023 Christian Olear +Copyright (c) 2024 Christian Olear Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the diff --git a/src/Validator.php b/src/Validator.php index 1f08583..3c02ebc 100644 --- a/src/Validator.php +++ b/src/Validator.php @@ -429,7 +429,7 @@ private static function getValidUrlComponents(string $url, bool $onlyAbsoluteUrl if ( is_array($components) && !empty($components) && - ($onlyAbsoluteUrl === false || filter_var($url, FILTER_VALIDATE_URL) !== false) + ($onlyAbsoluteUrl === false || (array_key_exists('scheme', $components) && !empty($components['scheme']))) ) { $components = self::filterEmptyStringComponents($components); $validComponents = self::validateUrlComponents($components); diff --git a/tests/ResolverTest.php b/tests/ResolverTest.php index 8c33d7a..1b8ef44 100644 --- a/tests/ResolverTest.php +++ b/tests/ResolverTest.php @@ -116,6 +116,10 @@ $relativeBaseUrl = new Url('/foo/bar?query=string#fragment'); $resolved = $resolver->resolve('https://www.example.com/examples', $relativeBaseUrl); $this->assertEquals('https://www.example.com/examples', $resolved); + + $baseUrl = new Url('https://www.example.com/foo'); + $resolved = $resolver->resolve('https://www.example.com/foo/bar-bür-bör', $baseUrl); + $this->assertEquals('https://www.example.com/foo/bar-b%C3%BCr-b%C3%B6r', $resolved); }); test('ResolvePaths', function () { diff --git a/tests/ValidatorTest.php b/tests/ValidatorTest.php index b9bbddf..14f4394 100644 --- a/tests/ValidatorTest.php +++ b/tests/ValidatorTest.php @@ -120,6 +120,13 @@ $this->assertNull(Validator::absoluteUrl('/foo/bar?query=string#fragment')); }); +test('validate an absolute URL containing non ASCII characters', function () { + $this->assertEquals( + 'https://www.example.com/f%C3%B6%C3%B6', + Validator::absoluteUrl('https://www.example.com/föö') + ); +}); + test('ValidateAbsoluteUrlAndComponents', function () { assertArrayContains( Validator::absoluteUrlAndComponents('https://www.crwlr.software/packages/url/v0.1.2#installation'),