File tree Expand file tree Collapse file tree 2 files changed +46
-1
lines changed
Expand file tree Collapse file tree 2 files changed +46
-1
lines changed Original file line number Diff line number Diff line change @@ -16,7 +16,7 @@ class RedirectUri
1616 */
1717 public function __construct (string $ redirectUri )
1818 {
19- if (! filter_var ( $ redirectUri , \ FILTER_VALIDATE_URL )) {
19+ if (1 !== preg_match ( ' /^[a-zA-Z][a-zA-Z0-9+.-]*:(?:\/\/[^\/\s?#]+(?:\/[^\s?#]*)?|\/[^\s?#]*)?(?:\?[^\s#]*)?(?:#[^\s]*)?$/ ' , $ redirectUri )) {
2020 throw new \RuntimeException (\sprintf ('The \'%s \' string is not a valid URI. ' , $ redirectUri ));
2121 }
2222
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ declare (strict_types=1 );
4+
5+ namespace League \Bundle \OAuth2ServerBundle \Tests \Unit ;
6+
7+ use League \Bundle \OAuth2ServerBundle \ValueObject \RedirectUri ;
8+ use PHPUnit \Framework \TestCase ;
9+
10+ final class RedirectUriTest extends TestCase
11+ {
12+ public function exceptionRedirectUriProvider (): array
13+ {
14+ return [
15+ ['invalid ' ],
16+ ['http://invalid url ' ],
17+ ['http:/invalid ' ],
18+ ['http:/invalid.com ' ],
19+ ['http:/invalid.com/test ' ],
20+ ];
21+ }
22+
23+ /**
24+ * @dataProvider exceptionRedirectUriProvider
25+ */
26+ public function testInvalidRedirectUris ($ data ): void
27+ {
28+ $ this ->expectException (\RuntimeException::class);
29+
30+ new RedirectUri ($ data [0 ]);
31+ }
32+
33+ public function testValidRedirectUris (): void
34+ {
35+ // Test standard URIs
36+ $ this ->assertIsObject (new RedirectUri ('http://github.com ' ));
37+ $ this ->assertIsObject (new RedirectUri ('http://github.com/test ' ));
38+ $ this ->assertIsObject (new RedirectUri ('http://github.com/test?query=test ' ));
39+
40+ // Test mobile URIs
41+ $ this ->assertIsObject (new RedirectUri ('com.my.app:/ ' ));
42+ $ this ->assertIsObject (new RedirectUri ('com.my.app:/callback ' ));
43+ $ this ->assertIsObject (new RedirectUri ('myapp://callback#token=123 ' ));
44+ }
45+ }
You can’t perform that action at this time.
0 commit comments