-
-
Notifications
You must be signed in to change notification settings - Fork 197
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes #253. The new `html_input` option allows 3 different behaviors: - `strip` HTML input - `allow` HTML input - `escape` HTML input
- Loading branch information
Showing
12 changed files
with
216 additions
and
1 deletion.
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
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,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
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