bugdown: Fix handling of twitter-format links that aren't actually tweets.

(imported from commit 60512147d8d303ff07cf1e86306fd14b1490e708)
This commit is contained in:
Tim Abbott
2013-05-29 15:38:16 -04:00
parent 1cf2d993a6
commit 2b1799b71c
3 changed files with 12 additions and 1 deletions

View File

@@ -302,10 +302,14 @@ class InlineInterestingLinkProcessor(markdown.treeprocessors.Treeprocessor):
if rendered_tweet:
# Only render at most one tweet per message
continue
twitter_data = self.twitter_link(url)
if twitter_data is None:
# This link is not actually a tweet known to twitter
continue
rendered_tweet = True
div = markdown.util.etree.SubElement(root, "div")
div.set("class", "inline-preview-twitter")
div.insert(0, self.twitter_link(url))
div.insert(0, twitter_data)
continue
if embedly_client.is_supported(url):
embedly_urls.append(url)

View File

@@ -2,6 +2,8 @@
import simplejson
def twitter(tweet_id):
if tweet_id not in ["112652479837110273", "287977969287315456", "287977969287315457"]:
return None
return simplejson.loads("""{
"coordinates": null,
"created_at": "Sat Sep 10 22:23:38 +0000 2011",

View File

@@ -2239,6 +2239,11 @@ xxxxxxx</strong></p>\n<p>xxxxxxx xxxxx xxxx xxxxx:<br>\n<code>xxxxxx</code>: xxx
converted = convert(msg)
self.assertEqual(converted, '<p>%s</p>' % make_link('http://www.twitter.com/wdaher/status/2879779692873154569'))
# id too large (i.e. tweet doesn't exist)
msg = 'http://www.twitter.com/wdaher/status/999999999999999999'
converted = convert(msg)
self.assertEqual(converted, '<p>%s</p>' % make_link('http://www.twitter.com/wdaher/status/999999999999999999'))
msg = 'http://www.twitter.com/wdaher/status/287977969287315456'
converted = convert(msg)
self.assertEqual(converted, '<p>%s</p>\n%s' % (make_link('http://www.twitter.com/wdaher/status/287977969287315456'),