From b459b3459437c963392350ee6cf35eff9fcb01ff Mon Sep 17 00:00:00 2001 From: Ignace Nyamagana Butera Date: Wed, 29 Jun 2022 09:47:44 +0200 Subject: [PATCH] Fix isCrossOrigin implementation to work with any PSR-7 UriInterface implementation --- CHANGELOG.md | 20 +++++++++++++++++++- composer.json | 1 + src/UriInfo.php | 4 ++-- src/UriInfoTest.php | 2 ++ 4 files changed, 24 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 65004ee4..e457beac 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,25 @@ All Notable changes to `League\Uri` will be documented in this file -## [6.7.0](https://github.com/thephpleague/uri/compare/6.6.0...6.7.0) - 2022-06-28 +## [6.7.1](https://github.com/thephpleague/uri/compare/6.7.0...6.7.1) - 2022-06-29 + +### Added + +- None + +### Fixed + +- `UriInfo::isCrossOrigin` method is fix to make it work with any PSR-7 compliant object [205](https://github.com/thephpleague/uri/pull/205) + +### Deprecated + +- None + +### Remove + +- None + +## [6.7.0](https://github.com/thephpleague/uri/compare/6.6.0...6.7.0) - 2022-06-29 ### Added diff --git a/composer.json b/composer.json index 4d361cec..28edbd84 100644 --- a/composer.json +++ b/composer.json @@ -51,6 +51,7 @@ }, "require-dev": { "friendsofphp/php-cs-fixer": "^v3.3.2", + "nyholm/psr7": "^1.5", "php-http/psr7-integration-tests": "^1.1", "phpstan/phpstan": "^1.2.0", "phpstan/phpstan-deprecation-rules": "^1.0", diff --git a/src/UriInfo.php b/src/UriInfo.php index 683b832e..ec8473c5 100644 --- a/src/UriInfo.php +++ b/src/UriInfo.php @@ -208,8 +208,8 @@ public static function getOrigin($uri): ?string */ public static function isCrossOrigin($uri, $base_uri): bool { - return null === ($uriString = self::getOrigin($uri)) - || null === ($baseUriString = self::getOrigin($base_uri)) + return null === ($uriString = self::getOrigin(Uri::createFromUri($uri))) + || null === ($baseUriString = self::getOrigin(Uri::createFromUri($base_uri))) || $uriString !== $baseUriString; } } diff --git a/src/UriInfoTest.php b/src/UriInfoTest.php index 68d40e80..adfbd07b 100644 --- a/src/UriInfoTest.php +++ b/src/UriInfoTest.php @@ -11,6 +11,7 @@ namespace League\Uri; +use Nyholm\Psr7\Uri as Psr7Uri; use PHPUnit\Framework\TestCase; use Psr\Http\Message\UriInterface as Psr7UriInterface; use TypeError; @@ -222,6 +223,7 @@ public function getOriginProvider(): array public function testIsCrossOrigin(string $original, string $modified, bool $expected): void { self::assertSame($expected, UriInfo::isCrossOrigin(Uri::createFromString($original), Http::createFromString($modified))); + self::assertSame($expected, UriInfo::isCrossOrigin(new Psr7Uri($original), new Psr7Uri($modified))); } /**