From: Adam Sampson Date: Sun, 12 Jul 2015 13:23:46 +0000 (+0100) Subject: Don't crash when feedparser returns an unformattable date. X-Git-Tag: v2.21~4 X-Git-Url: http://git.ozo.com/?a=commitdiff_plain;h=22bab00f7a2b3d96000e64b79cf2b0d73e35bb65;p=rawdog%2F.git Don't crash when feedparser returns an unformattable date. --- diff --git a/NEWS b/NEWS index 0ae388c..1905acf 100644 --- a/NEWS +++ b/NEWS @@ -12,6 +12,11 @@ Fix some style problems reported by pylint. Use cStringIO rather than StringIO in all modules (rather than some using one and some using the other). +Don't crash when feedparser returns a date that Python can't format. +Since feedparser's date parser is pretty liberal, it can occasionally +interpret an invalid date incorrectly (e.g. treating a time zone as a +year number). + - rawdog 2.20 Add a test for the maxage option (suggested by joelmo). diff --git a/rawdoglib/rawdog.py b/rawdoglib/rawdog.py index 3721f9d..ca66568 100644 --- a/rawdoglib/rawdog.py +++ b/rawdoglib/rawdog.py @@ -73,7 +73,10 @@ def get_system_encoding(): def safe_ftime(format, t): """Format a time value into a string in the current locale (as time.strftime), but encode the result as ASCII HTML.""" - u = unicode(time.strftime(format, t), get_system_encoding()) + try: + u = unicode(time.strftime(format, t), get_system_encoding()) + except ValueError, e: + u = u"(bad time %s; %s)" % (repr(t), str(e)) return encode_references(u) def format_time(secs, config): diff --git a/test-rawdog b/test-rawdog index eadf2d6..9ee1736 100755 --- a/test-rawdog +++ b/test-rawdog @@ -1279,6 +1279,39 @@ if [ -n "$ja_LC_ALL" ]; then contains $statedir/output.html "HEADING-Tuesday" "ITEMDATE-Tuesday" fi +begin "two-digit year with timezone" +# As of 2015-07, feedparser treats the time zone as the year number in the date +# below -- seen in the real world in . +# But time.strftime doesn't know how to format dates in the year 300 AD! +cat >$httpdir/feed.rss < + + example-feed-title + http://example.org/ + example-feed-description + + example-item-title + http://example.org/item + Fri, 20 Mar 15 17:32:14 +0300 + + + +EOF +add "feed 0 $httpurl/feed.rss" +runs -uw + +begin "year before 1000" +make_atom10 $httpdir/feed.atom +add "feed 0 $httpurl/feed.atom" +cat >$statedir/plugins/mangle.py <$httpdir/feed.atom <