Browse Source

Replace invalid xml utf-8 chars in tag contents including in attribute values.

Feed::utf8_for_xml() method used in the Feed::makeNode() method.
drikc 4 years ago
parent
commit
a7a85a356e
2 changed files with 4 additions and 2 deletions
  1. 3
    1
      Feed.php
  2. 1
    1
      Item.php

+ 3
- 1
Feed.php View File

@@ -183,7 +183,7 @@ abstract class Feed
183 183
     */
184 184
     public function setChannelElement($elementName, $content, $attributes = null, $multiple = false)
185 185
     {
186
-        $entity['content'] = self::utf8_for_xml($content);
186
+        $entity['content'] = $content;
187 187
         $entity['attributes'] = $attributes;
188 188
 
189 189
         if ($multiple === TRUE)
@@ -699,6 +699,7 @@ abstract class Feed
699 699
 
700 700
         if (is_array($attributes) && count($attributes) > 0) {
701 701
             foreach ($attributes as $key => $value) {
702
+                $value = self::utf8_for_xml($value);
702 703
                 $value = htmlspecialchars($value);
703 704
                 $attrText .= " $key=\"$value\"";
704 705
             }
@@ -717,6 +718,7 @@ abstract class Feed
717 718
                 $nodeText .= $this->makeNode($key, $value);
718 719
             }
719 720
         } else {
721
+            $tagContent = self::utf8_for_xml($tagContent);
720 722
             $nodeText .= (in_array($tagName, $this->CDATAEncoding)) ? $this->sanitizeCDATA($tagContent) : htmlspecialchars($tagContent);
721 723
         }
722 724
 

+ 1
- 1
Item.php View File

@@ -95,7 +95,7 @@ class Item
95 95
         }
96 96
 
97 97
         $this->elements[$key]['name']       = $elementName;
98
-        $this->elements[$key]['content']    = Feed::utf8_for_xml($content);
98
+        $this->elements[$key]['content']    = $content;
99 99
         $this->elements[$key]['attributes'] = $attributes;
100 100
 
101 101
         return $this;