Skip to content

Commit

Permalink
Unescape escaped HTML in titles (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
markvanlan committed Jan 15, 2021
1 parent 3fab154 commit 45b174a
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
3 changes: 2 additions & 1 deletion app/models/discourse_rss_polling/feed_item.rb
Expand Up @@ -24,7 +24,8 @@ def content

def title
unclean_title = @accessor.element_content(:title)&.force_encoding('UTF-8')&.scrub
TextCleaner.clean_title(TextSentinel.title_sentinel(unclean_title).text).presence
unclean_title = TextCleaner.clean_title(TextSentinel.title_sentinel(unclean_title).text).presence
CGI::unescapeHTML(unclean_title) if unclean_title
end

private
Expand Down
19 changes: 19 additions & 0 deletions spec/fixtures/files/escaped_html.atom
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<feed
xmlns="http://www.w3.org/2005/Atom">
<title>Discourse</title>
<link href="https://blog.discourse.org/feed/atom/" rel="self" type="application/atom+xml"/>
<updated>2019-08-21T01:42:02Z</updated>
<id>https://blog.discourse.org/feed/atom/</id>
<entry>
<id>https://blog.discourse.org/?p=pollfeedspec</id>
<title type="html"><![CDATA[Wellington: &#8220;Progress is hard!&#8221; Other cities: &#8220;Hold my beer&#8221;]]></title>
<author>
<name>xrav3nz</name>
</author>
<link href="https://blog.discourse.org/2017/09/poll-feed-spec-fixture/" rel="alternate" type="text/html"/>
<published>2019-08-16T21:46:39Z</published>
<updated>2019-08-16T21:46:39Z</updated>
<summary type="html">Here are some random descriptions...</summary>
</entry>
</feed>
13 changes: 13 additions & 0 deletions spec/models/feed_item_spec.rb
Expand Up @@ -34,6 +34,19 @@
)
end

context 'escaped title' do
let(:raw_feed) { rss_polling_file_fixture('escaped_html.atom').read }
let(:feed) { RSS::Parser.parse(raw_feed) }
let(:raw_feed_item) { feed.entries.first }

include_examples(
'correctly parses the feed',
content: 'Here are some random descriptions...',
url: 'https://blog.discourse.org/2017/09/poll-feed-spec-fixture/',
title: 'Wellington: “Progress is hard!” Other cities: “Hold my beer”',
)
end

context 'ATOM item with content element' do
let(:feed) { RSS::Parser.parse(file_from_fixtures('feed.atom', 'feed')) }
let(:raw_feed_item) { feed.entries.first }
Expand Down

0 comments on commit 45b174a

Please sign in to comment.