Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #39 from ckdake/master

Adds basic exception handling for some invalid data
  • Loading branch information...
commit d0aa7ce29b52343956702ffb7236d400819d47b7 2 parents aacf0c1 + 0b30ec6
@youpy authored
View
2  lib/lastfm/response.rb
@@ -7,6 +7,8 @@ class Response
def initialize(body)
@xml = XmlSimple.xml_in(body, 'ForceArray' => ['image', 'tag', 'user', 'event', 'correction'])
+ rescue REXML::ParseException
+ @xml = XmlSimple.xml_in(body.encode(Encoding.find("ISO-8859-1"), :undef => :replace), 'ForceArray' => ['image', 'tag', 'user', 'event', 'correction'])
end
def success?
View
18 spec/fixtures/user_get_recent_tracks_malformed.xml
@@ -0,0 +1,18 @@
+<?xml version="1.0"?>
+<lfm status="ok">
+ <recenttracks user="RJ" page="1" perPage="10" totalPages="3019">
+ <track>
+ <artist mbid="">￾䬀愀瀀 匀氀愀瀀</artist>
+ <name>￾匀琀爀漀戀攀 䰀椀最栀琀猀 ㈀ 䤀戀椀稀愀 ⠀䐀攀愀搀洀愀甀㔀 瘀猀 䔀氀氀椀攀 䜀漀甀氀搀椀渀最 瘀猀 匀眀攀搀椀猀栀 䠀漀甀猀攀 䴀愀昀椀愀 瘀猀 䘀攀爀最椀攀 瘀猀 䰀椀氀 䨀漀渀⤀</name>
+ <streamable>0</streamable>
+ <mbid></mbid>
+ <album mbid="">￾䔀愀爀洀椀氀欀⸀挀漀洀 ⴀ ⌀䴀愀猀栀甀瀀䴀漀渀搀愀礀</album>
+ <url>http://www.last.fm/music/%EF%BF%BE%E4%AC%80%E6%84%80%E7%80%80%E2%80%80%E5%8C%80%E6%B0%80%E6%84%80%E7%80%80/_/%EF%BF%BE%E5%8C%80%E7%90%80%E7%88%80%E6%BC%80%E6%88%80%E6%94%80%E2%80%80%E4%B0%80%E6%A4%80%E6%9C%80%E6%A0%80%E7%90%80%E7%8C%80%E2%80%80%E3%88%80%E2%80%80%E4%A4%80%E6%88%80%E6%A4%80%E7%A8%80%E6%84%80%E2%80%80%E2%A0%80%E4%90%80%E6%94%80%E6%84%80%E6%90%80%E6%B4%80%E6%84%80%E7%94%80%E3%94%80%E2%80%80%E7%98%80%E7%8C%80%E2%80%80%E4%94%80%E6%B0%80%E6%B0%80%E6%A4%80%E6%94%80%E2%80%80%E4%9C%80%E6%BC%80%E7%94%80%E6%B0%80%E6%90%80%E6%A4%80%E6%B8%80%E6%9C%80%E2%80%80%E7%98%80%E7%8C%80%E2%80%80%E5%8C%80%E7%9C%80%E6%94%80%E6%90%80%E6%A4%80%E7%8C%80%E6%A0%80%E2%80%80%E4%A0%80%E6%BC%80%E7%94%80%E7%8C%80%E6%94%80%E2%80%80%E4%B4%80%E6%84%80%E6%98%80%E6%A4%80%E6%84%80%E2%80%80%E7%98%80%E7%8C%80%E2%80%80%E4%98%80%E6%94%80%E7%88%80%E6%9C%80%E6%A4%80%E6%94%80%E2%80%80%E7%98%80%E7%8C%80%E2%80%80%E4%B0%80%E6%A4%80%E6%B0%80%E2%80%80%E4%A8%80%E6%BC%80%E6%B8%80%E2%A4%80</url>
+ <image size="small"></image>
+ <image size="medium"></image>
+ <image size="large"></image>
+ <image size="extralarge"></image>
+ <date uts="1338664693">2 Jun 2012, 19:18</date>
+ </track>
+ </recenttracks>
+</lfm>
View
11 spec/method_specs/user_spec.rb
@@ -210,6 +210,17 @@
tracks[1]['artist']['content'].should == 'Kylie Minogue'
tracks.size.should == 2
end
+
+ it 'should not error when a user\'s recent tracks includes malformed data' do
+ @lastfm.should_receive(:request).with('user.getRecentTracks', {
+ :user => 'test',
+ :page => nil,
+ :limit => nil,
+ :to => nil,
+ :from => nil
+ }).and_return(make_response('user_get_recent_tracks_malformed'))
+ tracks = @lastfm.user.get_recent_tracks(:user => 'test')
+ end
end
describe '#get_top_tags' do
Please sign in to comment.
Something went wrong with that request. Please try again.