Skip to content

Commit

Permalink
Fix isCrossOrigin implementation to work with any PSR-7 UriInterface …
Browse files Browse the repository at this point in the history
…implementation
  • Loading branch information
nyamsprod committed Jun 29, 2022
1 parent 9bae56e commit b8b87f2
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 2 deletions.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions src/UriInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
2 changes: 2 additions & 0 deletions src/UriInfoTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)));
}

/**
Expand Down

0 comments on commit b8b87f2

Please sign in to comment.