Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions .github/workflows/php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ jobs:
strategy:
fail-fast: false
matrix:
php-version: ['8.3', '8.4', '8.5']
php-version: ['8.5', '8.6']

uses: simplesamlphp/simplesamlphp-test-framework/.github/workflows/reusable_phplinter.yml@v1
uses: simplesamlphp/simplesamlphp-test-framework/.github/workflows/reusable_phplinter.yml@v2
secrets: inherit
with:
php-version: ${{ matrix.php-version }}
Expand All @@ -31,7 +31,7 @@ jobs:
strategy:
fail-fast: false

uses: simplesamlphp/simplesamlphp-test-framework/.github/workflows/reusable_linter.yml@v1
uses: simplesamlphp/simplesamlphp-test-framework/.github/workflows/reusable_linter.yml@v2
secrets: inherit
with:
enable_eslinter: false
Expand All @@ -47,7 +47,7 @@ jobs:
fail-fast: false
matrix:
operating-system: [ubuntu-latest]
php-versions: ['8.3', '8.4', '8.5']
php-versions: ['8.5', '8.6']

steps:
- name: Setup PHP, with composer and extensions
Expand All @@ -57,7 +57,7 @@ jobs:
php-version: ${{ matrix.php-versions }}
extensions: ctype, date, filter, intl, pcre, sodium, spl
tools: composer
ini-values: error_reporting=E_ALL
ini-values: display_errors=on, error_reporting=E_ALL
coverage: pcov

- name: Setup problem matchers for PHP
Expand Down Expand Up @@ -109,7 +109,7 @@ jobs:
fail-fast: true
matrix:
operating-system: [windows-latest]
php-versions: ['8.3', '8.4', '8.5']
php-versions: ['8.5']

steps:
- name: Setup PHP, with composer and extensions
Expand Down Expand Up @@ -218,7 +218,7 @@ jobs:
uses: shivammathur/setup-php@v2
with:
# Should be the lowest supported version
php-version: '8.3'
php-version: '8.5'
extensions: ctype, date, filter, pcre, sodium, spl
tools: composer
coverage: none
Expand Down
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,19 @@
}
],
"require": {
"php": "^8.3",
"php": "^8.5",
"ext-date": "*",
"ext-filter": "*",
"ext-pcre": "*",
"ext-spl": "*",
"ext-uri": "*",

"guzzlehttp/psr7": "~2.8",
"webmozart/assert": "~2.1"
},
"require-dev": {
"ext-intl": "*",

"simplesamlphp/simplesamlphp-test-framework": "~1.11"
"simplesamlphp/simplesamlphp-test-framework": "~2"
},
"autoload": {
"psr-4": {
Expand All @@ -40,7 +40,7 @@
},
"extra": {
"branch-alias": {
"dev-master": "v2.1.x-dev"
"dev-master": "v3.0.x-dev"
}
},
"config": {
Expand Down
46 changes: 33 additions & 13 deletions src/URITrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@

namespace SimpleSAML\Assert;

use GuzzleHttp\Psr7\Exception\MalformedUriException;
use GuzzleHttp\Psr7\Uri;
use InvalidArgumentException;
use Uri\InvalidUriException;
use Uri\Rfc3986\Uri;
use Uri\WhatWg\InvalidUrlException;
use Uri\WhatWg\Url;

use function sprintf;
use function strlen;
Expand All @@ -25,7 +27,7 @@ trait URITrait
* not handle any custom exception passed to it. *
***********************************************************************************/

private static Uri $uri;
private static Uri|Url $uri;


/**
Expand All @@ -34,7 +36,7 @@ protected static function validURN(string $value, string $message = ''): string
{
try {
self::$uri = new Uri($value);
} catch (MalformedUriException $e) {
} catch (InvalidUriException $e) {
throw new InvalidArgumentException(sprintf(
$message ?: '\'%s\' is not a valid RFC3986 compliant URI',
$value,
Expand All @@ -60,17 +62,17 @@ protected static function validURN(string $value, string $message = ''): string
protected static function validURL(string $value, string $message = ''): string
{
try {
self::$uri = new Uri($value);
} catch (MalformedUriException $e) {
self::$uri = new Url($value);
} catch (InvalidUrlException $e) {
throw new InvalidArgumentException(sprintf(
$message ?: '\'%s\' is not a valid RFC3986 compliant URI',
$message ?: '\'%s\' is not a valid WhatWg compliant URI',
$value,
));
}

if (self::$uri->getScheme() !== 'http' && self::$uri->getScheme() !== 'https') {
throw new InvalidArgumentException(sprintf(
$message ?: '\'%s\' is not a valid RFC2396 compliant URL',
$message ?: '\'%s\' is not a valid WhatWg compliant URL',
$value,
));
}
Expand All @@ -83,13 +85,31 @@ protected static function validURL(string $value, string $message = ''): string
*/
protected static function validURI(string $value, string $message = ''): string
{
$failure = false;
try {
self::$uri = new Uri($value);
} catch (MalformedUriException $e) {
throw new InvalidArgumentException(sprintf(
$message ?: '\'%s\' is not a valid RFC3986 compliant URI',
$value,
));
} catch (InvalidUriException $e) {
$failure = true;
}

if ($failure === true) {
try {
self::$uri = new Url($value);
} catch (InvalidUrlException $e) {
throw new InvalidArgumentException(sprintf(
$message ?: '\'%s\' is not a valid WhatWg compliant URL',
$value,
));
} finally {
$failure = false;
}

if ($failure === true) {
throw new InvalidArgumentException(sprintf(
$message ?: '\'%s\' is not a valid RFC3986 compliant URI',
$value,
));
}
}

return $value;
Expand Down
1 change: 0 additions & 1 deletion tests/Assert/AssertTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ public function testValueToString(mixed $value, string $expected): void
{
$assert = new Assert();
$method = new ReflectionMethod(Assert::class, 'valueToString');
$method->setAccessible(true);

$this->assertEquals($expected, $method->invoke($assert, $value));
}
Expand Down
4 changes: 2 additions & 2 deletions tests/Assert/URITest.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@ public static function provideURI(): array
'intl' => [true, 'https://niño.com'],
'spn' => [true, 'spn:a4cf592f-a64c-46ff-a788-b260f474525b'],
'typos' => [true, 'https//www.uni.l/en/'],
'spaces' => [true, 'this is silly'],
'spaces' => [false, 'this is silly'],
'empty' => [true, ''],
'azure-common' => [true, 'https://sts.windows.net/{tenantid}/'],
'azure-common' => [true, 'https://sts.windows.net/123e4567-e89b-12d3-a456-426614174000/'],
'email' => [true, 'scoobydoo@whereareyou.org'],
];
}
Expand Down
Loading