Skip to content

Commit

Permalink
Improve handling of Atom text content with CDATA
Browse files Browse the repository at this point in the history
  • Loading branch information
fguillot committed Mar 21, 2021
1 parent c8c1f05 commit 5877048
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
8 changes: 5 additions & 3 deletions reader/atom/atom_10.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions reader/atom/atom_10_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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>`

Expand Down Expand Up @@ -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>`
Expand Down

0 comments on commit 5877048

Please sign in to comment.