1
0
Fork 0

Improve handling of Atom text content with CDATA

This commit is contained in:
Frédéric Guillot 2021-03-20 20:38:29 -07:00 committed by fguillot
parent c8c1f05328
commit 5877048749
2 changed files with 7 additions and 5 deletions

View file

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

View file

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