diff --git a/src/ValueObject/RedirectUri.php b/src/ValueObject/RedirectUri.php index 7ecd066e..90a88a1b 100644 --- a/src/ValueObject/RedirectUri.php +++ b/src/ValueObject/RedirectUri.php @@ -16,7 +16,7 @@ class RedirectUri */ public function __construct(string $redirectUri) { - if (!filter_var($redirectUri, \FILTER_VALIDATE_URL)) { + if (1 !== preg_match('/^[a-zA-Z][a-zA-Z0-9+.-]*:(?:\/\/[^\/\s?#]+(?:\/[^\s?#]*)?|\/[^\s?#]*)?(?:\?[^\s#]*)?(?:#[^\s]*)?$/', $redirectUri)) { throw new \RuntimeException(\sprintf('The \'%s\' string is not a valid URI.', $redirectUri)); } diff --git a/tests/Unit/RedirectUriTest.php b/tests/Unit/RedirectUriTest.php new file mode 100644 index 00000000..eda5fabe --- /dev/null +++ b/tests/Unit/RedirectUriTest.php @@ -0,0 +1,45 @@ +expectException(\RuntimeException::class); + + new RedirectUri($data[0]); + } + + public function testValidRedirectUris(): void + { + // Test standard URIs + $this->assertIsObject(new RedirectUri('http://github.com')); + $this->assertIsObject(new RedirectUri('http://github.com/test')); + $this->assertIsObject(new RedirectUri('http://github.com/test?query=test')); + + // Test mobile URIs + $this->assertIsObject(new RedirectUri('com.my.app:/')); + $this->assertIsObject(new RedirectUri('com.my.app:/callback')); + $this->assertIsObject(new RedirectUri('myapp://callback#token=123')); + } +}