summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatt Farina <[email protected]>2013-05-27 20:40:16 -0400
committerMatt Farina <[email protected]>2013-05-27 20:40:16 -0400
commit6242eebec76c28a8ed9e8d8491f8c33e8fd85fb1 (patch)
treea1b94d0d8110fdc5f13b60c4db8ad65ec8cdc63b
parent0e7cd49d390160603563c17c76dea82eba1824b9 (diff)
Fixed cdata and text handling.
wholeText on a text node holds the text of logically adjacent text. That means a new line followed by cdata following by spaces and/or a new line will all be in the cdata wholeText. This change fixes our handling to use data rather than wholeText. Also fixed the cdata regex tests.
-rw-r--r--src/HTML5/Serializer/OutputRules.php6
-rw-r--r--test/HTML5/Serializer/SerializerTest.php3
2 files changed, 4 insertions, 5 deletions
diff --git a/src/HTML5/Serializer/OutputRules.php b/src/HTML5/Serializer/OutputRules.php
index 5780d61..3db857b 100644
--- a/src/HTML5/Serializer/OutputRules.php
+++ b/src/HTML5/Serializer/OutputRules.php
@@ -64,17 +64,17 @@ class OutputRules {
*/
public function text($ele) {
if (isset($ele->parentNode) && Elements::isA($ele->parentNode->tagName, Elements::TEXT_RAW)) {
- $this->wr($ele->wholeText);
+ $this->wr($ele->data);
return;
}
// FIXME: This probably needs some flags set.
- $this->wr($this->enc($ele->wholeText));
+ $this->wr($this->enc($ele->data));
}
public function cdata($ele) {
- $this->wr('<![CDATA[')->wr($ele->wholeText)->wr(']]>');
+ $this->wr('<![CDATA[')->wr($ele->data)->wr(']]>');
}
public function comment($ele) {
diff --git a/test/HTML5/Serializer/SerializerTest.php b/test/HTML5/Serializer/SerializerTest.php
index 4a28c54..234cca4 100644
--- a/test/HTML5/Serializer/SerializerTest.php
+++ b/test/HTML5/Serializer/SerializerTest.php
@@ -130,9 +130,8 @@ class SerializerTest extends \HTML5\Tests\TestCase {
$this->assertRegExp('|<!-- This is a test. -->|', $res);
}
- // FAILS because the parser converts CDATA to a comment. Issue #2.
public function testCDATA() {
$res = $this->cycle($this->prepareHtml('a<![CDATA[ This <is> a test. ]]>b'));
- $this->assertRegExp('|<![CDATA[ This <is> a test. ]]>|', $res);
+ $this->assertRegExp('|<!\[CDATA\[ This <is> a test\. \]\]>|', $res);
}
}