Browse Source

Improve handling of Atom text content with CDATA

Frédéric Guillot 5 years ago
parent
commit
5877048749
2 changed files with 7 additions and 5 deletions
  1. 5 3
      reader/atom/atom_10.go
  2. 2 2
      reader/atom/atom_10_test.go

+ 5 - 3
reader/atom/atom_10.go

@@ -231,10 +231,12 @@ func (a *atom10Text) String() string {
 	var content string
 
 	switch {
-	case strings.HasPrefix(a.InnerXML, `<![CDATA[`):
-		content = a.CharData
 	case a.Type == "", a.Type == "text", a.Type == "text/plain":
-		content = a.InnerXML
+		if strings.HasPrefix(a.InnerXML, `<![CDATA[`) {
+			content = html.EscapeString(a.CharData)
+		} else {
+			content = a.InnerXML
+		}
 	case a.Type == "xhtml":
 		if a.XHTMLRootElement.InnerXML != "" {
 			content = a.XHTMLRootElement.InnerXML

+ 2 - 2
reader/atom/atom_10_test.go

@@ -531,7 +531,7 @@ func TestParseEntryWithTextSummary(t *testing.T) {
 		<link href="http://example.org/d"/>
 		<id>urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a</id>
 		<updated>2003-12-13T18:30:02Z</updated>
-		<summary type="text"><![CDATA[AT&amp;T &lt;S&gt;]]></summary>
+		<summary type="text"><![CDATA[AT&T <S>]]></summary>
 	  </entry>
 	</feed>`
 
@@ -583,7 +583,7 @@ func TestParseEntryWithTextContent(t *testing.T) {
 		<link href="http://example.org/d"/>
 		<id>urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a</id>
 		<updated>2003-12-13T18:30:02Z</updated>
-		<content><![CDATA[AT&amp;T &lt;S&gt;]]></content>
+		<content><![CDATA[AT&T <S>]]></content>
 	  </entry>
 
 	</feed>`