summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAsmir Mustafic <[email protected]>2014-02-10 09:00:59 +0100
committerAsmir Mustafic <[email protected]>2014-02-10 09:00:59 +0100
commit1a89c6b18851f446c4842514c93e8b6698ae0b2d (patch)
treeceda3cd0407522a8a6bc27b21bb41915ca9ac5cd /src
parent7713a8b8c0fa603732fb442c026d0144347cbd39 (diff)
tests and html5 standards
Diffstat (limited to 'src')
-rw-r--r--src/HTML5/Serializer/OutputRules.php18
1 files changed, 13 insertions, 5 deletions
diff --git a/src/HTML5/Serializer/OutputRules.php b/src/HTML5/Serializer/OutputRules.php
index 48cc307..6ef9f12 100644
--- a/src/HTML5/Serializer/OutputRules.php
+++ b/src/HTML5/Serializer/OutputRules.php
@@ -163,7 +163,7 @@ class OutputRules implements \HTML5\Serializer\RulesInterface {
$len = $map->length;
for ($i = 0; $i < $len; ++$i) {
$node = $map->item($i);
- $val = $this->enc($node->value, true);
+ $val = $this->enc($node->value, TRUE);
// XXX: The spec says that we need to ensure that anything in
// the XML, XMLNS, or XLink NS's should use the canonical
@@ -240,26 +240,34 @@ class OutputRules implements \HTML5\Serializer\RulesInterface {
*
* @param string $text
* text to encode.
+ * @param boolean $attribute
+ * True if we are encoding an attrubute, false otherwise
*
* @return string
* The encoded text.
*/
- protected function enc($text, $attribute = false) {
- $quotes = !$attribute?0:ENT_QUOTES;
+ protected function enc($text, $attribute = FALSE) {
+ $quotes = $attribute ? ENT_COMPAT : 0;
// Escape rather than encode all entities.
- if (!$this->encode) {
+ if (!$this->encode && $attribute) {
+ return strtr($text, array('"'=>'&quot;','&'=>'&amp;'));
+ } elseif (!$this->encode) {
return htmlspecialchars($text, $quotes, 'UTF-8');
}
// If we are in PHP 5.4+ we can use the native html5 entity functionality.
if (defined('ENT_HTML5')) {
- $flags = ENT_HTML5 | ENT_SUBSTITUTE|$quotes;
+ $flags = ENT_HTML5 | ENT_SUBSTITUTE | $quotes;
$ret = htmlentities($text, $flags, 'UTF-8', FALSE);
}
// If a version earlier than 5.4 html5 entities are not entirely handled.
// This manually handles them.
else {
+ $cusotmMap = \HTML5\Serializer\HTML5Entities::$map;
+ if (!($cusotmMap & ENT_COMPAT)){
+ unset($cusotmMap["'"]);
+ }
$ret = strtr($text, \HTML5\Serializer\HTML5Entities::$map);
}
return $ret;