This repository has been archived by the owner on May 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #59 from olegatro/relative-links
add allow_relative_links setting
- Loading branch information
Showing
10 changed files
with
129 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,7 @@ public function provideUrls() | |
'allowedSchemes' => ['http', 'https'], | ||
'allowedHosts' => null, | ||
'allowMailTo' => false, | ||
'allowRelativeLinks' => false, | ||
'forceHttps' => false, | ||
'input' => 'https://trusted.com/link.php', | ||
'output' => 'https://trusted.com/link.php', | ||
|
@@ -32,6 +33,7 @@ public function provideUrls() | |
'allowedSchemes' => ['http', 'https'], | ||
'allowedHosts' => ['trusted.com'], | ||
'allowMailTo' => false, | ||
'allowRelativeLinks' => false, | ||
'forceHttps' => false, | ||
'input' => 'https://trusted.com/link.php', | ||
'output' => 'https://trusted.com/link.php', | ||
|
@@ -41,6 +43,7 @@ public function provideUrls() | |
'allowedSchemes' => ['http', 'https'], | ||
'allowedHosts' => ['trusted.com'], | ||
'allowMailTo' => false, | ||
'allowRelativeLinks' => false, | ||
'forceHttps' => false, | ||
'input' => 'https://untrusted.com/link.php', | ||
'output' => null, | ||
|
@@ -50,6 +53,7 @@ public function provideUrls() | |
'allowedSchemes' => ['http', 'https'], | ||
'allowedHosts' => null, | ||
'allowMailTo' => false, | ||
'allowRelativeLinks' => false, | ||
'forceHttps' => false, | ||
'input' => '/link.php', | ||
'output' => null, | ||
|
@@ -59,16 +63,28 @@ public function provideUrls() | |
'allowedSchemes' => ['http', 'https'], | ||
'allowedHosts' => null, | ||
'allowMailTo' => true, | ||
'allowRelativeLinks' => false, | ||
'forceHttps' => false, | ||
'input' => '/link.php', | ||
'output' => null, | ||
]; | ||
|
||
yield [ | ||
'allowedSchemes' => ['http', 'https'], | ||
'allowedHosts' => null, | ||
'allowMailTo' => true, | ||
'allowRelativeLinks' => true, | ||
'forceHttps' => false, | ||
'input' => '/link.php', | ||
'output' => '/link.php', | ||
]; | ||
|
||
// Force HTTPS | ||
yield [ | ||
'allowedSchemes' => ['http', 'https'], | ||
'allowedHosts' => ['trusted.com'], | ||
'allowMailTo' => false, | ||
'allowRelativeLinks' => false, | ||
'forceHttps' => true, | ||
'input' => 'http://trusted.com/link.php', | ||
'output' => 'https://trusted.com/link.php', | ||
|
@@ -79,6 +95,7 @@ public function provideUrls() | |
'allowedSchemes' => ['http', 'https'], | ||
'allowedHosts' => null, | ||
'allowMailTo' => true, | ||
'allowRelativeLinks' => false, | ||
'forceHttps' => false, | ||
'input' => 'data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7', | ||
'output' => null, | ||
|
@@ -88,6 +105,7 @@ public function provideUrls() | |
'allowedSchemes' => ['http', 'https'], | ||
'allowedHosts' => null, | ||
'allowMailTo' => true, | ||
'allowRelativeLinks' => false, | ||
'forceHttps' => true, | ||
'input' => 'data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7', | ||
'output' => null, | ||
|
@@ -98,6 +116,7 @@ public function provideUrls() | |
'allowedSchemes' => ['http', 'https'], | ||
'allowedHosts' => null, | ||
'allowMailTo' => false, | ||
'allowRelativeLinks' => false, | ||
'forceHttps' => false, | ||
'input' => 'mailto:[email protected]', | ||
'output' => null, | ||
|
@@ -107,6 +126,7 @@ public function provideUrls() | |
'allowedSchemes' => ['http', 'https'], | ||
'allowedHosts' => null, | ||
'allowMailTo' => true, | ||
'allowRelativeLinks' => false, | ||
'forceHttps' => false, | ||
'input' => 'mailto:[email protected]', | ||
'output' => 'mailto:[email protected]', | ||
|
@@ -116,6 +136,7 @@ public function provideUrls() | |
'allowedSchemes' => ['http', 'https'], | ||
'allowedHosts' => ['trusted.com'], | ||
'allowMailTo' => true, | ||
'allowRelativeLinks' => false, | ||
'forceHttps' => false, | ||
'input' => 'mailto:[email protected]', | ||
'output' => 'mailto:[email protected]', | ||
|
@@ -125,6 +146,7 @@ public function provideUrls() | |
'allowedSchemes' => ['http', 'https'], | ||
'allowedHosts' => ['trusted.com'], | ||
'allowMailTo' => true, | ||
'allowRelativeLinks' => false, | ||
'forceHttps' => true, | ||
'input' => 'mailto:[email protected]', | ||
'output' => 'mailto:[email protected]', | ||
|
@@ -134,6 +156,7 @@ public function provideUrls() | |
'allowedSchemes' => ['http', 'https'], | ||
'allowedHosts' => null, | ||
'allowMailTo' => true, | ||
'allowRelativeLinks' => false, | ||
'forceHttps' => false, | ||
'input' => 'mailto:invalid', | ||
'output' => null, | ||
|
@@ -143,6 +166,7 @@ public function provideUrls() | |
'allowedSchemes' => ['http', 'https'], | ||
'allowedHosts' => null, | ||
'allowMailTo' => true, | ||
'allowRelativeLinks' => false, | ||
'forceHttps' => false, | ||
'input' => 'mailto:', | ||
'output' => null, | ||
|
@@ -152,6 +176,7 @@ public function provideUrls() | |
'allowedSchemes' => ['https'], | ||
'allowedHosts' => null, | ||
'allowMailTo' => true, | ||
'allowRelativeLinks' => false, | ||
'forceHttps' => false, | ||
'input' => 'http://trusted.com/link.php', | ||
'output' => null, | ||
|
@@ -161,8 +186,8 @@ public function provideUrls() | |
/** | ||
* @dataProvider provideUrls | ||
*/ | ||
public function testSanitize($allowedSchemes, $allowedHosts, $allowMailTo, $forceHttps, $input, $expected) | ||
public function testSanitize($allowedSchemes, $allowedHosts, $allowMailTo, $allowRelativeLinks, $forceHttps, $input, $expected) | ||
{ | ||
$this->assertSame($expected, (new AHrefSanitizer($allowedSchemes, $allowedHosts, $allowMailTo, $forceHttps))->sanitize($input)); | ||
$this->assertSame($expected, (new AHrefSanitizer($allowedSchemes, $allowedHosts, $allowMailTo, $allowRelativeLinks, $forceHttps))->sanitize($input)); | ||
} | ||
} |
Oops, something went wrong.