@@ -23,6 +23,7 @@ public function provideUrls()
2323 'allowedSchemes ' => ['http ' , 'https ' ],
2424 'allowedHosts ' => null ,
2525 'allowMailTo ' => false ,
26+ 'allowRelativeLinks ' => false ,
2627 'forceHttps ' => false ,
2728 'input ' => 'https://trusted.com/link.php ' ,
2829 'output ' => 'https://trusted.com/link.php ' ,
@@ -32,6 +33,7 @@ public function provideUrls()
3233 'allowedSchemes ' => ['http ' , 'https ' ],
3334 'allowedHosts ' => ['trusted.com ' ],
3435 'allowMailTo ' => false ,
36+ 'allowRelativeLinks ' => false ,
3537 'forceHttps ' => false ,
3638 'input ' => 'https://trusted.com/link.php ' ,
3739 'output ' => 'https://trusted.com/link.php ' ,
@@ -41,6 +43,7 @@ public function provideUrls()
4143 'allowedSchemes ' => ['http ' , 'https ' ],
4244 'allowedHosts ' => ['trusted.com ' ],
4345 'allowMailTo ' => false ,
46+ 'allowRelativeLinks ' => false ,
4447 'forceHttps ' => false ,
4548 'input ' => 'https://untrusted.com/link.php ' ,
4649 'output ' => null ,
@@ -50,6 +53,7 @@ public function provideUrls()
5053 'allowedSchemes ' => ['http ' , 'https ' ],
5154 'allowedHosts ' => null ,
5255 'allowMailTo ' => false ,
56+ 'allowRelativeLinks ' => false ,
5357 'forceHttps ' => false ,
5458 'input ' => '/link.php ' ,
5559 'output ' => null ,
@@ -59,16 +63,28 @@ public function provideUrls()
5963 'allowedSchemes ' => ['http ' , 'https ' ],
6064 'allowedHosts ' => null ,
6165 'allowMailTo ' => true ,
66+ 'allowRelativeLinks ' => false ,
6267 'forceHttps ' => false ,
6368 'input ' => '/link.php ' ,
6469 'output ' => null ,
6570 ];
6671
72+ yield [
73+ 'allowedSchemes ' => ['http ' , 'https ' ],
74+ 'allowedHosts ' => null ,
75+ 'allowMailTo ' => true ,
76+ 'allowRelativeLinks ' => true ,
77+ 'forceHttps ' => false ,
78+ 'input ' => '/link.php ' ,
79+ 'output ' => '/link.php ' ,
80+ ];
81+
6782 // Force HTTPS
6883 yield [
6984 'allowedSchemes ' => ['http ' , 'https ' ],
7085 'allowedHosts ' => ['trusted.com ' ],
7186 'allowMailTo ' => false ,
87+ 'allowRelativeLinks ' => false ,
7288 'forceHttps ' => true ,
7389 'input ' => 'http://trusted.com/link.php ' ,
7490 'output ' => 'https://trusted.com/link.php ' ,
@@ -79,6 +95,7 @@ public function provideUrls()
7995 'allowedSchemes ' => ['http ' , 'https ' ],
8096 'allowedHosts ' => null ,
8197 'allowMailTo ' => true ,
98+ 'allowRelativeLinks ' => false ,
8299 'forceHttps ' => false ,
83100 'input ' => 'data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7 ' ,
84101 'output ' => null ,
@@ -88,6 +105,7 @@ public function provideUrls()
88105 'allowedSchemes ' => ['http ' , 'https ' ],
89106 'allowedHosts ' => null ,
90107 'allowMailTo ' => true ,
108+ 'allowRelativeLinks ' => false ,
91109 'forceHttps ' => true ,
92110 'input ' => 'data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7 ' ,
93111 'output ' => null ,
@@ -98,6 +116,7 @@ public function provideUrls()
98116 'allowedSchemes ' => ['http ' , 'https ' ],
99117 'allowedHosts ' => null ,
100118 'allowMailTo ' => false ,
119+ 'allowRelativeLinks ' => false ,
101120 'forceHttps ' => false ,
102121 'input ' => 'mailto:test@gmail.com ' ,
103122 'output ' => null ,
@@ -107,6 +126,7 @@ public function provideUrls()
107126 'allowedSchemes ' => ['http ' , 'https ' ],
108127 'allowedHosts ' => null ,
109128 'allowMailTo ' => true ,
129+ 'allowRelativeLinks ' => false ,
110130 'forceHttps ' => false ,
111131 'input ' => 'mailto:test@gmail.com ' ,
112132 'output ' => 'mailto:test@gmail.com ' ,
@@ -116,6 +136,7 @@ public function provideUrls()
116136 'allowedSchemes ' => ['http ' , 'https ' ],
117137 'allowedHosts ' => ['trusted.com ' ],
118138 'allowMailTo ' => true ,
139+ 'allowRelativeLinks ' => false ,
119140 'forceHttps ' => false ,
120141 'input ' => 'mailto:test@gmail.com ' ,
121142 'output ' => 'mailto:test@gmail.com ' ,
@@ -125,6 +146,7 @@ public function provideUrls()
125146 'allowedSchemes ' => ['http ' , 'https ' ],
126147 'allowedHosts ' => ['trusted.com ' ],
127148 'allowMailTo ' => true ,
149+ 'allowRelativeLinks ' => false ,
128150 'forceHttps ' => true ,
129151 'input ' => 'mailto:test@gmail.com ' ,
130152 'output ' => 'mailto:test@gmail.com ' ,
@@ -134,6 +156,7 @@ public function provideUrls()
134156 'allowedSchemes ' => ['http ' , 'https ' ],
135157 'allowedHosts ' => null ,
136158 'allowMailTo ' => true ,
159+ 'allowRelativeLinks ' => false ,
137160 'forceHttps ' => false ,
138161 'input ' => 'mailto:invalid ' ,
139162 'output ' => null ,
@@ -143,6 +166,7 @@ public function provideUrls()
143166 'allowedSchemes ' => ['http ' , 'https ' ],
144167 'allowedHosts ' => null ,
145168 'allowMailTo ' => true ,
169+ 'allowRelativeLinks ' => false ,
146170 'forceHttps ' => false ,
147171 'input ' => 'mailto: ' ,
148172 'output ' => null ,
@@ -152,6 +176,7 @@ public function provideUrls()
152176 'allowedSchemes ' => ['https ' ],
153177 'allowedHosts ' => null ,
154178 'allowMailTo ' => true ,
179+ 'allowRelativeLinks ' => false ,
155180 'forceHttps ' => false ,
156181 'input ' => 'http://trusted.com/link.php ' ,
157182 'output ' => null ,
@@ -161,8 +186,8 @@ public function provideUrls()
161186 /**
162187 * @dataProvider provideUrls
163188 */
164- public function testSanitize ($ allowedSchemes , $ allowedHosts , $ allowMailTo , $ forceHttps , $ input , $ expected )
189+ public function testSanitize ($ allowedSchemes , $ allowedHosts , $ allowMailTo , $ allowRelativeLinks , $ forceHttps , $ input , $ expected )
165190 {
166- $ this ->assertSame ($ expected , (new AHrefSanitizer ($ allowedSchemes , $ allowedHosts , $ allowMailTo , $ forceHttps ))->sanitize ($ input ));
191+ $ this ->assertSame ($ expected , (new AHrefSanitizer ($ allowedSchemes , $ allowedHosts , $ allowMailTo , $ allowRelativeLinks , $ forceHttps ))->sanitize ($ input ));
167192 }
168193}
0 commit comments