Skip to content

Commit e98e3e6

Browse files
Release 1.9.0 (#520)
1 parent 337e3ad commit e98e3e6

File tree

5 files changed

+128
-5
lines changed

5 files changed

+128
-5
lines changed

CHANGELOG.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,18 @@
33

44
All notable changes to this project will be documented in this file.
55

6-
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
7-
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
6+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
7+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
88

99

1010
## Unreleased
1111

12+
## 1.9.0 - 2022-06-20
13+
14+
### Added
15+
16+
- Added `UriComparator::isCrossOrigin` method
17+
1218
## 1.8.5 - 2022-03-20
1319

1420
### Fixed

README.md

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# PSR-7 Message Implementation
22

3-
This repository contains a full [PSR-7](http://www.php-fig.org/psr/psr-7/)
3+
This repository contains a full [PSR-7](https://www.php-fig.org/psr/psr-7/)
44
message implementation, several stream decorators, and some helpful
55
functionality like query string parsing.
66

@@ -659,7 +659,7 @@ manually but instead is used indirectly via `Psr\Http\Message\UriInterface::__to
659659

660660
`public static function fromParts(array $parts): UriInterface`
661661

662-
Creates a URI from a hash of [`parse_url`](http://php.net/manual/en/function.parse-url.php) components.
662+
Creates a URI from a hash of [`parse_url`](https://www.php.net/manual/en/function.parse-url.php) components.
663663

664664

665665
### `GuzzleHttp\Psr7\Uri::withQueryValue`
@@ -684,6 +684,16 @@ associative array of key => value.
684684
Creates a new URI with a specific query string value removed. Any existing query string values that exactly match the
685685
provided key are removed.
686686

687+
## Cross-Origin Detection
688+
689+
`GuzzleHttp\Psr7\UriComparator` provides methods to determine if a modified URL should be considered cross-origin.
690+
691+
### `GuzzleHttp\Psr7\UriComparator::isCrossOrigin`
692+
693+
`public static function isCrossOrigin(UriInterface $original, UriInterface $modified): bool`
694+
695+
Determines if a modified URL should be considered cross-origin with respect to an original URL.
696+
687697
## Reference Resolution
688698

689699
`GuzzleHttp\Psr7\UriResolver` provides methods to resolve a URI reference in the context of a base URI according
@@ -809,14 +819,24 @@ This of course assumes they will be resolved against the same base URI. If this
809819
equivalence or difference of relative references does not mean anything.
810820

811821

822+
## Version Guidance
823+
824+
| Version | Status | PHP Version |
825+
|---------|----------------|------------------|
826+
| 1.x | Security fixes | >=5.4,<8.1 |
827+
| 2.x | Latest | ^7.2.5 \|\| ^8.0 |
828+
829+
812830
## Security
813831

814832
If you discover a security vulnerability within this package, please send an email to security@tidelift.com. All security vulnerabilities will be promptly addressed. Please do not disclose security-related issues publicly until a fix has been announced. Please see [Security Policy](https://github.com/guzzle/psr7/security/policy) for more information.
815833

834+
816835
## License
817836

818837
Guzzle is made available under the MIT License (MIT). Please see [License File](LICENSE) for more information.
819838

839+
820840
## For Enterprise
821841

822842
Available as part of the Tidelift Subscription

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
},
6464
"extra": {
6565
"branch-alias": {
66-
"dev-master": "1.7-dev"
66+
"dev-master": "1.9-dev"
6767
}
6868
},
6969
"config": {

src/UriComparator.php

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?php
2+
3+
namespace GuzzleHttp\Psr7;
4+
5+
use Psr\Http\Message\UriInterface;
6+
7+
/**
8+
* Provides methods to determine if a modified URL should be considered cross-origin.
9+
*
10+
* @author Graham Campbell
11+
*/
12+
final class UriComparator
13+
{
14+
/**
15+
* Determines if a modified URL should be considered cross-origin with
16+
* respect to an original URL.
17+
*
18+
* @return bool
19+
*/
20+
public static function isCrossOrigin(UriInterface $original, UriInterface $modified)
21+
{
22+
if (\strcasecmp($original->getHost(), $modified->getHost()) !== 0) {
23+
return true;
24+
}
25+
26+
if ($original->getScheme() !== $modified->getScheme()) {
27+
return true;
28+
}
29+
30+
if (self::computePort($original) !== self::computePort($modified)) {
31+
return true;
32+
}
33+
34+
return false;
35+
}
36+
37+
/**
38+
* @return int
39+
*/
40+
private static function computePort(UriInterface $uri)
41+
{
42+
$port = $uri->getPort();
43+
44+
if (null !== $port) {
45+
return $port;
46+
}
47+
48+
return 'https' === $uri->getScheme() ? 443 : 80;
49+
}
50+
51+
private function __construct()
52+
{
53+
// cannot be instantiated
54+
}
55+
}

tests/UriComparatorTest.php

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
3+
namespace GuzzleHttp\Tests\Psr7;
4+
5+
use GuzzleHttp\Psr7\Uri;
6+
use GuzzleHttp\Psr7\UriComparator;
7+
8+
/**
9+
* @covers GuzzleHttp\Psr7\UriComparator
10+
*/
11+
class UriComparatorTest extends BaseTest
12+
{
13+
/**
14+
* @dataProvider getCrossOriginExamples
15+
*/
16+
public function testIsCrossOrigin($originalUri, $modifiedUri, $expected)
17+
{
18+
self::assertSame($expected, UriComparator::isCrossOrigin(new Uri($originalUri), new Uri($modifiedUri)));
19+
}
20+
21+
public function getCrossOriginExamples()
22+
{
23+
return [
24+
['http://example.com/123', 'http://example.com/', false],
25+
['http://example.com/123', 'http://example.com:80/', false],
26+
['http://example.com:80/123', 'http://example.com/', false],
27+
['http://example.com:80/123', 'http://example.com:80/', false],
28+
['http://example.com/123', 'https://example.com/', true],
29+
['http://example.com/123', 'http://www.example.com/', true],
30+
['http://example.com/123', 'http://example.com:81/', true],
31+
['http://example.com:80/123', 'http://example.com:81/', true],
32+
['https://example.com/123', 'https://example.com/', false],
33+
['https://example.com/123', 'https://example.com:443/', false],
34+
['https://example.com:443/123', 'https://example.com/', false],
35+
['https://example.com:443/123', 'https://example.com:443/', false],
36+
['https://example.com/123', 'http://example.com/', true],
37+
['https://example.com/123', 'https://www.example.com/', true],
38+
['https://example.com/123', 'https://example.com:444/', true],
39+
['https://example.com:443/123', 'https://example.com:444/', true],
40+
];
41+
}
42+
}

0 commit comments

Comments
 (0)