File tree Expand file tree Collapse file tree 2 files changed +75
-1
lines changed Expand file tree Collapse file tree 2 files changed +75
-1
lines changed Original file line number Diff line number Diff line change @@ -378,7 +378,8 @@ public static function home($scheme = false)
378
378
*/
379
379
public static function isRelative ($ url )
380
380
{
381
- return strncmp ($ url , '// ' , 2 ) && strpos ($ url , ':// ' ) === false ;
381
+ $ urlComponents = parse_url ($ url , PHP_URL_SCHEME );
382
+ return strncmp ($ url , '// ' , 2 ) && empty ($ urlComponents );
382
383
}
383
384
384
385
/**
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace yiiunit \framework \helpers ;
4
+
5
+ use PHPUnit \Framework \TestCase ;
6
+ use yii \helpers \BaseUrl ;
7
+
8
+ /**
9
+ * @group helpers
10
+ */
11
+ class BaseUrlTest extends TestCase
12
+ {
13
+
14
+ public function testIsRelativeWithAbsoluteUrlWillReturnFalse ()
15
+ {
16
+ $ this ->assertFalse (BaseUrl::isRelative ('https://acme.com/tnt-room=123 ' ));
17
+ }
18
+
19
+ public function testUrlStartingWithDoubleSlashesWillReturnFalse ()
20
+ {
21
+ $ this ->assertFalse (BaseUrl::isRelative ('//example.com ' ));
22
+ }
23
+
24
+ public function testIsRelativeWithRelativeUrlWillReturnTrue ()
25
+ {
26
+ $ this ->assertTrue (
27
+ BaseUrl::isRelative ('acme.com/tnt-room=123 ' )
28
+ );
29
+ }
30
+
31
+ public function testIsRelativeWithRelativeUrlHavingHttpsUrlAsParamValueWillReturnTrue ()
32
+ {
33
+ $ this ->assertTrue (BaseUrl::isRelative (
34
+ 'acme.com/tnt-room-link=https://asd.com '
35
+ ));
36
+ }
37
+
38
+ public function testIsRelativeWithAbsoluteUrlHavingHttpsUrlAsParamValueWillReturnFalse ()
39
+ {
40
+ $ this ->assertFalse (
41
+ BaseUrl::isRelative ('https://acme.com/tnt-link=https://tnt.com ' )
42
+ );
43
+ }
44
+
45
+ public function testIsRelativeWithA ()
46
+ {
47
+ $ this ->assertTrue (
48
+ BaseUrl::isRelative ('/name=bugs.bunny ' )
49
+ );
50
+ }
51
+
52
+ public function testIsRelativeWithFtpProtocolUrlWillReturnFalse ()
53
+ {
54
+ $ this ->assertFalse (
55
+ BaseUrl::isRelative ('ftp://ftp.acme.com/tnt-suppliers.txt ' )
56
+ );
57
+ }
58
+
59
+ public function testIsRelativeWithHttpUrl ()
60
+ {
61
+ $ this ->assertFalse (
62
+ BaseUrl::isRelative ('http://no-protection.acme.com ' )
63
+ );
64
+ }
65
+
66
+ public function testIsRelativeWithFileUrl ()
67
+ {
68
+ $ this ->assertFalse (
69
+ BaseUrl::isRelative ('file:///home/User/2ndFile.html ' )
70
+ );
71
+ }
72
+
73
+ }
You can’t perform that action at this time.
0 commit comments