-
-
Notifications
You must be signed in to change notification settings - Fork 193
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 #255 from mnapoli/html-input-escaping
Add a new `html_input` option
- Loading branch information
Showing
20 changed files
with
355 additions
and
4 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 |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?php | ||
|
||
namespace League\CommonMark\Tests\Functional; | ||
|
||
use League\CommonMark\CommonMarkConverter; | ||
use League\CommonMark\Environment; | ||
|
||
class HtmlInputTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
public function testDefaultConfig() | ||
{ | ||
$input = file_get_contents(__DIR__ . '/data/html_input/input.md'); | ||
$expectedOutput = trim(file_get_contents(__DIR__ . '/data/html_input/unsafe_output.html')); | ||
|
||
$converter = new CommonMarkConverter(); | ||
$actualOutput = trim($converter->convertToHtml($input)); | ||
|
||
$this->assertEquals($expectedOutput, $actualOutput); | ||
} | ||
|
||
public function testAllowHtmlInputConfig() | ||
{ | ||
$input = file_get_contents(__DIR__ . '/data/html_input/input.md'); | ||
$expectedOutput = trim(file_get_contents(__DIR__ . '/data/html_input/unsafe_output.html')); | ||
|
||
$converter = new CommonMarkConverter(['html_input' => Environment::HTML_INPUT_ALLOW]); | ||
$actualOutput = trim($converter->convertToHtml($input)); | ||
|
||
$this->assertEquals($expectedOutput, $actualOutput); | ||
} | ||
|
||
public function testEscapeHtmlInputConfig() | ||
{ | ||
$input = file_get_contents(__DIR__ . '/data/html_input/input.md'); | ||
$expectedOutput = trim(file_get_contents(__DIR__ . '/data/html_input/escaped_output.html')); | ||
|
||
$converter = new CommonMarkConverter(['html_input' => Environment::HTML_INPUT_ESCAPE]); | ||
$actualOutput = trim($converter->convertToHtml($input)); | ||
|
||
$this->assertEquals($expectedOutput, $actualOutput); | ||
} | ||
|
||
public function testStripHtmlInputConfig() | ||
{ | ||
$input = file_get_contents(__DIR__ . '/data/html_input/input.md'); | ||
$expectedOutput = trim(file_get_contents(__DIR__ . '/data/html_input/safe_output.html')); | ||
|
||
$converter = new CommonMarkConverter(['html_input' => Environment::HTML_INPUT_STRIP]); | ||
$actualOutput = trim($converter->convertToHtml($input)); | ||
|
||
$this->assertEquals($expectedOutput, $actualOutput); | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
namespace League\CommonMark\Tests\Functional; | ||
|
||
use League\CommonMark\CommonMarkConverter; | ||
|
||
class SafeLinksTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
public function testDefaultConfig() | ||
{ | ||
$input = file_get_contents(__DIR__ . '/data/safe_links/input.md'); | ||
$expectedOutput = trim(file_get_contents(__DIR__ . '/data/safe_links/unsafe_output.html')); | ||
|
||
$converter = new CommonMarkConverter(); | ||
$actualOutput = trim($converter->convertToHtml($input)); | ||
|
||
$this->assertEquals($expectedOutput, $actualOutput); | ||
} | ||
|
||
public function testSafeConfig() | ||
{ | ||
$input = file_get_contents(__DIR__ . '/data/safe_links/input.md'); | ||
$expectedOutput = trim(file_get_contents(__DIR__ . '/data/safe_links/safe_output.html')); | ||
|
||
$converter = new CommonMarkConverter(['allow_unsafe_links' => false]); | ||
$actualOutput = trim($converter->convertToHtml($input)); | ||
|
||
$this->assertEquals($expectedOutput, $actualOutput); | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<div onclick="alert('XSS')">click me</div> | ||
<script>alert("XSS")</script> | ||
<script> | ||
alert("XSS"); | ||
</script> |
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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<div onclick="alert('XSS')">click me</div> | ||
|
||
<script>alert("XSS")</script> | ||
|
||
<script> | ||
alert("XSS"); | ||
</script> |
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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
|
||
|
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<div onclick="alert('XSS')">click me</div> | ||
<script>alert("XSS")</script> | ||
<script> | ||
alert("XSS"); | ||
</script> |
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
[Click me](javascript:alert('XSS')) | ||
|
||
<javascript:alert("XSS")> | ||
|
||
![Inline image](data:image/gif;base64,R0lGODlhEAAQAMQAAORHHOVSKudfOulrSOp3WOyDZu6QdvCchPGolfO0o/XBs/fNwfjZ0frl3/zy7////wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAkAABAALAAAAAAQABAAAAVVICSOZGlCQAosJ6mu7fiyZeKqNKToQGDsM8hBADgUXoGAiqhSvp5QAnQKGIgUhwFUYLCVDFCrKUE1lBavAViFIDlTImbKC5Gm2hB0SlBCBMQiB0UjIQA7) |
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<p><a>Click me</a></p> | ||
<p><a>javascript:alert("XSS")</a></p> | ||
<p><img src="data:image/gif;base64,R0lGODlhEAAQAMQAAORHHOVSKudfOulrSOp3WOyDZu6QdvCchPGolfO0o/XBs/fNwfjZ0frl3/zy7////wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAkAABAALAAAAAAQABAAAAVVICSOZGlCQAosJ6mu7fiyZeKqNKToQGDsM8hBADgUXoGAiqhSvp5QAnQKGIgUhwFUYLCVDFCrKUE1lBavAViFIDlTImbKC5Gm2hB0SlBCBMQiB0UjIQA7" alt="Inline image" /></p> |
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<p><a href="javascript:alert('XSS')">Click me</a></p> | ||
<p><a href="javascript:alert(%22XSS%22)">javascript:alert("XSS")</a></p> | ||
<p><img src="data:image/gif;base64,R0lGODlhEAAQAMQAAORHHOVSKudfOulrSOp3WOyDZu6QdvCchPGolfO0o/XBs/fNwfjZ0frl3/zy7////wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAkAABAALAAAAAAQABAAAAVVICSOZGlCQAosJ6mu7fiyZeKqNKToQGDsM8hBADgUXoGAiqhSvp5QAnQKGIgUhwFUYLCVDFCrKUE1lBavAViFIDlTImbKC5Gm2hB0SlBCBMQiB0UjIQA7" alt="Inline image" /></p> |
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
Oops, something went wrong.