summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/HTML5/Serializer/OutputRules.php4
-rw-r--r--test/HTML5/Serializer/OutputRulesTest.php46
2 files changed, 34 insertions, 16 deletions
diff --git a/src/HTML5/Serializer/OutputRules.php b/src/HTML5/Serializer/OutputRules.php
index bc57346..15e6c6e 100644
--- a/src/HTML5/Serializer/OutputRules.php
+++ b/src/HTML5/Serializer/OutputRules.php
@@ -245,7 +245,7 @@ class OutputRules implements \HTML5\Serializer\RulesInterface {
* The encoded text.
*/
protected function enc($text) {
- $flags = ENT_QUOTES;
+ $flags = 0;
// Escape rather than encode all entities.
if (!$this->encode) {
@@ -254,7 +254,7 @@ class OutputRules implements \HTML5\Serializer\RulesInterface {
// If we are in PHP 5.4+ we can use the native html5 entity functionality.
if (defined('ENT_HTML5')) {
- $flags = ENT_HTML5 | ENT_SUBSTITUTE | ENT_QUOTES;
+ $flags = ENT_HTML5 | ENT_SUBSTITUTE;
$ret = htmlentities($text, $flags, 'UTF-8', FALSE);
}
// If a version earlier than 5.4 html5 entities are not entirely handled.
diff --git a/test/HTML5/Serializer/OutputRulesTest.php b/test/HTML5/Serializer/OutputRulesTest.php
index 61e2d50..9c20a7f 100644
--- a/test/HTML5/Serializer/OutputRulesTest.php
+++ b/test/HTML5/Serializer/OutputRulesTest.php
@@ -22,7 +22,7 @@ class OutputRulesTest extends \HTML5\Tests\TestCase {
/**
* Using reflection we make a protected method accessible for testing.
- *
+ *
* @param string $name
* The name of the method on the Traverser class to test.
*
@@ -216,7 +216,7 @@ class OutputRulesTest extends \HTML5\Tests\TestCase {
$item = $dom->getElementById('foo');
$r->text($item->firstChild);
- $this->assertEquals('<script>alert("hi");</script>', stream_get_contents($stream, -1, 0));
+ $this->assertEquals('<script>alert("hi");</script>', stream_get_contents($stream, -1, 0));
}
function testNl() {
@@ -235,24 +235,42 @@ class OutputRulesTest extends \HTML5\Tests\TestCase {
$this->assertEquals('foo', stream_get_contents($s, -1, 0));
}
- function testEnc() {
-
- // Test basic escaping of text.
- $tests = array(
- '&\'<>"' => '&amp;&#039;&lt;&gt;&quot;',
- 'This + is. a < test' => 'This + is. a &lt; test',
+ function getEncData(){
+ return array(
+ array('&\'<>"', '&amp;\'&lt;&gt;"'),
+ array('This + is. a < test', 'This + is. a &lt; test'),
+ array('.+#', '.+#'),
);
+ }
+
+ function getEncWithEntiyesData(){
+ return array(
+ array('.+#', '&period;&plus;&num;'),
+ );
+ }
+
+ /**
+ * Test basic escaping of text.
+ * @dataProvider getEncData
+ */
+ function testEnc($test, $expected) {
list($o, $s) = $this->getOutputRules();
$m = $this->getProtectedMethod('enc');
- foreach ($tests as $test => $expected) {
- $this->assertEquals($expected, $m->invoke($o, $test));
- }
+ $this->assertEquals($expected, $m->invoke($o, $test));
- list($o, $s) = $this->getOutputRules(array('encode_entities' => TRUE));
- $m = $this->getProtectedMethod('enc');
+ }
+
+ /**
+ * Test basic escaping of text.
+ * @dataProvider getEncWithEntiyesData
+ */
+ function testEncWithEntities($test, $expected) {
- $this->assertEquals('&period;&plus;&num;', $m->invoke($o, '.+#'));
+ list($o, $s) = $this->getOutputRules(array('encode_entities' => TRUE));
+ $m = $this->getProtectedMethod('enc');
+
+ $this->assertEquals($expected, $m->invoke($o, $test));
}
function testAttrs() {