Skip to content

Instantly share code, notes, and snippets.

@deborasetton
Last active August 29, 2015 14:10
Show Gist options
  • Select an option

  • Save deborasetton/1cf4e11e66249f4d8ade to your computer and use it in GitHub Desktop.

Select an option

Save deborasetton/1cf4e11e66249f4d8ade to your computer and use it in GitHub Desktop.
Test case for Feedjira issue #253
bundle install
bundle exec ruby feedjira_test.rb
bundle exec ruby monkeypatched_feedjira_test.rb
require 'feedjira'
xml = <<-XML
<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<title>RSS Title</title>
<item>
<description>This entry is ok.</description>
</item>
<item>
<description>Here is an invalid character: \xE9!</description>
</item>
<item>
<description>This other entry is also ok, but never reached.</description>
</item>
</channel>
</rss>
XML
# Force Feedjira::Parser::RSS.able_to_parse? to return true
xml.force_encoding("ASCII-8BIT")
# Callback that is supposed to be called
callback = ->(*args) { puts "Callback was called with args: "; puts args.inspect }
# This line should cause callback to be called, but nothing happens
feed = Feedjira::Feed.parse(xml, &callback)
# Inspect feed object
puts "Feed entries: #{feed.entries.count}"
source 'https://rubygems.org'
gem 'feedjira', git: 'https://github.com/feedjira/feedjira.git'
require 'feedjira'
# Monkey-patch Feedjira
module Feedjira::FeedUtilities::ClassMethods
def parse(xml, &block)
xml = xml.lstrip
xml = preprocess(xml) if preprocess_xml
super xml, block
end
end
# Run the same script
load './feedjira_test.rb'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment