diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index 6dc7c97..27d3e42 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -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 }} @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/composer.json b/composer.json index 7af6d4e..6920e3b 100644 --- a/composer.json +++ b/composer.json @@ -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": { @@ -40,7 +40,7 @@ }, "extra": { "branch-alias": { - "dev-master": "v2.1.x-dev" + "dev-master": "v3.0.x-dev" } }, "config": { diff --git a/src/URITrait.php b/src/URITrait.php index 84fb2c9..383df83 100644 --- a/src/URITrait.php +++ b/src/URITrait.php @@ -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; @@ -25,7 +27,7 @@ trait URITrait * not handle any custom exception passed to it. * ***********************************************************************************/ - private static Uri $uri; + private static Uri|Url $uri; /** @@ -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, @@ -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, )); } @@ -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; diff --git a/tests/Assert/AssertTest.php b/tests/Assert/AssertTest.php index aebd747..7c79957 100644 --- a/tests/Assert/AssertTest.php +++ b/tests/Assert/AssertTest.php @@ -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)); } diff --git a/tests/Assert/URITest.php b/tests/Assert/URITest.php index e9317a4..a9c7f10 100644 --- a/tests/Assert/URITest.php +++ b/tests/Assert/URITest.php @@ -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'], ]; }