Skip to content

Commit 0984792

Browse files
committed
Migrate from league to guzzle for uri validation
1 parent bc1a149 commit 0984792

File tree

3 files changed

+17
-17
lines changed

3 files changed

+17
-17
lines changed

composer.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@
1919
"ext-pcre": "*",
2020
"ext-spl": "*",
2121

22-
"league/uri-interfaces": "^7.4",
23-
"webmozart/assert": "^1.11"
22+
"guzzlehttp/psr7": "~2.7.0",
23+
"webmozart/assert": "~1.11.0"
2424
},
2525
"require-dev": {
2626
"ext-intl": "*",
2727

28-
"simplesamlphp/simplesamlphp-test-framework": "^1.7"
28+
"simplesamlphp/simplesamlphp-test-framework": "~1.8.0"
2929
},
3030
"autoload": {
3131
"psr-4": {

src/CustomAssertionTrait.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44

55
namespace SimpleSAML\Assert;
66

7+
use GuzzleHttp\Psr7\Exception\MalformedUriException;
8+
use GuzzleHttp\Psr7\Uri;
79
use InvalidArgumentException;
8-
use League\Uri\Exceptions\SyntaxError;
9-
use League\Uri\UriString;
1010

1111
use function array_map;
1212
use function base64_decode;
@@ -197,17 +197,17 @@ private static function notInArray($value, array $values, string $message = ''):
197197
private static function validURN(string $value, string $message = ''): void
198198
{
199199
try {
200-
$uri = UriString::parse($value);
201-
} catch (SyntaxError $e) {
200+
$uri = new Uri($value);
201+
} catch (MalformedUriException $e) {
202202
throw new InvalidArgumentException(sprintf(
203203
$message ?: '\'%s\' is not a valid RFC3986 compliant URI',
204204
$value,
205205
));
206206
}
207207

208208
if (
209-
$uri['scheme'] !== 'urn'
210-
|| (($uri['scheme'] !== null) && $uri['path'] !== substr($value, strlen($uri['scheme']) + 1))
209+
$uri->getScheme() !== 'urn'
210+
|| (($uri->getScheme() !== null) && $uri->getPath() !== substr($value, strlen($uri->getScheme()) + 1))
211211
) {
212212
throw new InvalidArgumentException(sprintf(
213213
$message ?: '\'%s\' is not a valid RFC8141 compliant URN',
@@ -224,15 +224,15 @@ private static function validURN(string $value, string $message = ''): void
224224
private static function validURL(string $value, string $message = ''): void
225225
{
226226
try {
227-
$uri = UriString::parse($value);
228-
} catch (SyntaxError $e) {
227+
$uri = new Uri($value);
228+
} catch (MalformedUriException $e) {
229229
throw new InvalidArgumentException(sprintf(
230230
$message ?: '\'%s\' is not a valid RFC3986 compliant URI',
231231
$value,
232232
));
233233
}
234234

235-
if ($uri['scheme'] !== 'http' && $uri['scheme'] !== 'https') {
235+
if ($uri->getScheme() !== 'http' && $uri->getScheme() !== 'https') {
236236
throw new InvalidArgumentException(sprintf(
237237
$message ?: '\'%s\' is not a valid RFC2396 compliant URL',
238238
$value,
@@ -248,8 +248,8 @@ private static function validURL(string $value, string $message = ''): void
248248
private static function validURI(string $value, string $message = ''): void
249249
{
250250
try {
251-
UriString::parse($value);
252-
} catch (SyntaxError $e) {
251+
new Uri($value);
252+
} catch (MalformedUriException $e) {
253253
throw new InvalidArgumentException(sprintf(
254254
$message ?: '\'%s\' is not a valid RFC3986 compliant URI',
255255
$value,

tests/Assert/URITest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public static function provideURI(): array
7575
'urn' => [true, 'urn:x-simplesamlphp:phpunit'],
7676
'same-doc' => [true, '#_53d830ab1be17291a546c95c7f1cdf8d3d23c959e6'],
7777
'url' => [true, 'https://www.simplesamlphp.org'],
78-
'invalid_char' => [false, 'https://a⒈com'],
78+
'utf8_char' => [true, 'https://aä.com'],
7979
'intl' => [true, 'https://niño.com'],
8080
'spn' => [true, 'spn:a4cf592f-a64c-46ff-a788-b260f474525b'],
8181
'typos' => [true, 'https//www.uni.l/en/'],
@@ -95,7 +95,7 @@ public static function provideURL(): array
9595
'url' => [true, 'https://www.simplesamlphp.org'],
9696
'same-doc' => [false, '#_53d830ab1be17291a546c95c7f1cdf8d3d23c959e6'],
9797
'urn' => [false, 'urn:x-simplesamlphp:phpunit'],
98-
'invalid_char' => [false, 'https://a⒈com'],
98+
'utf8_char' => [true, 'https://aä.com'],
9999
'intl' => [true, 'https://niño.com'],
100100
'spn' => [false, 'spn:a4cf592f-a64c-46ff-a788-b260f474525b'],
101101
'typos' => [false, 'https//www.uni.l/en/'],
@@ -114,7 +114,7 @@ public static function provideURN(): array
114114
'newline_suffix' => [false, "urn:x-simplesamlphp:phpunit\n"],
115115
'url' => [false, 'https://www.simplesamlphp.org'],
116116
'same-doc' => [false, '#_53d830ab1be17291a546c95c7f1cdf8d3d23c959e6'],
117-
'invalid_char' => [false, 'https://a⒈com'],
117+
'utf8_char' => [false, 'https://aä.com'],
118118
'intl' => [false, 'https://niño.com'],
119119
'spn' => [false, 'spn:a4cf592f-a64c-46ff-a788-b260f474525b'],
120120
'typos' => [false, 'https//www.uni.l/en/'],

0 commit comments

Comments
 (0)