Permalink
Browse files

fixed bug with provider rule endpoint already containing query in url…

… (http://..../?....)

updated initial_data.json to include myspace provider rule which revealed the bug
  • Loading branch information...
1 parent 0b09321 commit 8ec587a99460e6bafdcbb346f03c4f6a5165f086 @jonathanstasiak jonathanstasiak committed Mar 26, 2010
Showing with 5 additions and 3 deletions.
  1. +4 −2 oembed/core.py
  2. +1 −1 oembed/fixtures/initial_data.json
View
@@ -152,8 +152,10 @@ def replace(text, max_width=MAX_WIDTH, max_height=MAX_HEIGHT):
except KeyError:
try:
# Build the URL based on the properties defined in the OEmbed spec.
- url = u"%s?url=%s&maxwidth=%s&maxheight=%s&format=%s" % (
- rule.endpoint, part, max_width, max_height, FORMAT
+ sep = "?" in rule.endpoint and "&" or "?"
+ clean_part = urllib2.quote(part)
+ url = u"%s%surl=%s&maxwidth=%s&maxheight=%s&format=%s" % (
+ rule.endpoint, sep, clean_part, max_width, max_height, FORMAT
)
# Fetch the link and parse the JSON.
resp = simplejson.loads(fetch(url))
@@ -1 +1 @@
-[{"pk": 1, "model": "oembed.providerrule", "fields": {"regex": "http:\/\/\\S*?flickr.com\/\\S*", "endpoint": "http:\/\/www.flickr.com\/services\/oembed\/", "name": "Flickr", "format": 1}}, {"pk": 2, "model": "oembed.providerrule", "fields": {"regex": "http:\/\/\\S*?viddler.com\/\\S*", "endpoint": "http:\/\/lab.viddler.com\/services\/oembed\/", "name": "Viddler", "format": 1}}, {"pk": 3, "model": "oembed.providerrule", "fields": {"regex": "http:\/\/qik.com\/\\S*", "endpoint": "http:\/\/qik.com\/api\/oembed.json", "name": "Qik", "format": 1}}, {"pk": 4, "model": "oembed.providerrule", "fields": {"regex": "http:\/\/\\S*?pownce.com\/\\S*", "endpoint": "http:\/\/api.pownce.com\/2.1\/oembed.json", "name": "Pownce", "format": 1}}, {"pk": 5, "model": "oembed.providerrule", "fields": {"regex": "http:\/\/\\S*?revision3.com\/\\S*", "endpoint": "http:\/\/revision3.com\/api\/oembed\/", "name": "Revision3", "format": 1}}, {"pk": 6, "model": "oembed.providerrule", "fields": {"regex": "http:\/\/\\S*.amazon.(com|co.uk|de|ca|jp)\/\\S*\/(gp\/product|o\/ASIN|obidos\/ASIN|dp)\/\\S*", "endpoint": "http:\/\/oohembed.com\/oohembed\/", "name": "Amazon Product Image (OohEmbed)", "format": 1}}, {"pk": 7, "model": "oembed.providerrule", "fields": {"regex": "http:\/\/\\S*.collegehumor.com\/video:\\S*", "endpoint": "http:\/\/oohembed.com\/oohembed\/", "name": "CollegeHumor Video (OohEmbed)", "format": 1}}, {"pk": 8, "model": "oembed.providerrule", "fields": {"regex": "http:\/\/\\S*.funnyordie.com\/videos\/\\S*", "endpoint": "http:\/\/oohembed.com\/oohembed\/", "name": "Funny or Die Video (OohEmbed)", "format": 1}}, {"pk": 9, "model": "oembed.providerrule", "fields": {"regex": "http:\/\/video.google.com\/videoplay?\\S*", "endpoint": "http:\/\/oohembed.com\/oohembed\/", "name": "Google Video (OohEmbed)", "format": 1}}, {"pk": 10, "model": "oembed.providerrule", "fields": {"regex": "http:\/\/www.hulu.com\/watch\/\\S*", "endpoint": "http:\/\/oohembed.com\/oohembed\/", "name": "Hulu (OohEmbed)", "format": 1}}, {"pk": 11, "model": "oembed.providerrule", "fields": {"regex": "http:\/\/\\S*.metacafe.com\/watch\/\\S*", "endpoint": "http:\/\/oohembed.com\/oohembed\/", "name": "Metacafe (OohEmbed)", "format": 1}}, {"pk": 12, "model": "oembed.providerrule", "fields": {"regex": "http:\/\/twitter.com\/\\S*\/statuses\/\\S*", "endpoint": "http:\/\/oohembed.com\/oohembed\/", "name": "Twitter Status (OohEmbed)", "format": 1}}, {"pk": 13, "model": "oembed.providerrule", "fields": {"regex": "http:\/\/\\S*.wikipedia.org\/wiki\/\\S*", "endpoint": "http:\/\/oohembed.com\/oohembed\/", "name": "Wikipedia (OohEmbed)", "format": 1}}, {"pk": 14, "model": "oembed.providerrule", "fields": {"regex": "http:\/\/\\S*.youtube.com\/watch\\S*", "endpoint": "http:\/\/oohembed.com\/oohembed\/", "name": "YouTube (OohEmbed)", "format": 1}}, {"pk": 15, "model": "oembed.providerrule", "fields": {"regex": "http:\/\/vimeo.com\/\\S*", "endpoint": "http:\/\/vimeo.com\/api\/oembed.json", "name": "Vimeo", "format": 1}}]
+[{"pk": 1, "model": "oembed.providerrule", "fields": {"regex": "http://\\S*?flickr.com/\\S*", "endpoint": "http://www.flickr.com/services/oembed/", "name": "Flickr", "format": 1}}, {"pk": 2, "model": "oembed.providerrule", "fields": {"regex": "http://\\S*?viddler.com/\\S*", "endpoint": "http://lab.viddler.com/services/oembed/", "name": "Viddler", "format": 1}}, {"pk": 3, "model": "oembed.providerrule", "fields": {"regex": "http://qik.com/\\S*", "endpoint": "http://qik.com/api/oembed.json", "name": "Qik", "format": 1}}, {"pk": 4, "model": "oembed.providerrule", "fields": {"regex": "http://\\S*?pownce.com/\\S*", "endpoint": "http://api.pownce.com/2.1/oembed.json", "name": "Pownce", "format": 1}}, {"pk": 5, "model": "oembed.providerrule", "fields": {"regex": "http://\\S*?revision3.com/\\S*", "endpoint": "http://revision3.com/api/oembed/", "name": "Revision3", "format": 1}}, {"pk": 6, "model": "oembed.providerrule", "fields": {"regex": "http://\\S*.amazon.(com|co.uk|de|ca|jp)/\\S*/(gp/product|o/ASIN|obidos/ASIN|dp)/\\S*", "endpoint": "http://oohembed.com/oohembed/", "name": "Amazon Product Image (OohEmbed)", "format": 1}}, {"pk": 7, "model": "oembed.providerrule", "fields": {"regex": "http://\\S*.collegehumor.com/video:\\S*", "endpoint": "http://oohembed.com/oohembed/", "name": "CollegeHumor Video (OohEmbed)", "format": 1}}, {"pk": 8, "model": "oembed.providerrule", "fields": {"regex": "http://\\S*.funnyordie.com/videos/\\S*", "endpoint": "http://oohembed.com/oohembed/", "name": "Funny or Die Video (OohEmbed)", "format": 1}}, {"pk": 9, "model": "oembed.providerrule", "fields": {"regex": "http://video.google.com/videoplay?\\S*", "endpoint": "http://oohembed.com/oohembed/", "name": "Google Video (OohEmbed)", "format": 1}}, {"pk": 10, "model": "oembed.providerrule", "fields": {"regex": "http://www.hulu.com/watch/\\S*", "endpoint": "http://oohembed.com/oohembed/", "name": "Hulu (OohEmbed)", "format": 1}}, {"pk": 11, "model": "oembed.providerrule", "fields": {"regex": "http://\\S*.metacafe.com/watch/\\S*", "endpoint": "http://oohembed.com/oohembed/", "name": "Metacafe (OohEmbed)", "format": 1}}, {"pk": 12, "model": "oembed.providerrule", "fields": {"regex": "http://twitter.com/\\S*/statuses/\\S*", "endpoint": "http://oohembed.com/oohembed/", "name": "Twitter Status (OohEmbed)", "format": 1}}, {"pk": 13, "model": "oembed.providerrule", "fields": {"regex": "http://\\S*.wikipedia.org/wiki/\\S*", "endpoint": "http://oohembed.com/oohembed/", "name": "Wikipedia (OohEmbed)", "format": 1}}, {"pk": 14, "model": "oembed.providerrule", "fields": {"regex": "http://\\S*.youtube.com/watch\\S*", "endpoint": "http://oohembed.com/oohembed/", "name": "YouTube (OohEmbed)", "format": 1}}, {"pk": 15, "model": "oembed.providerrule", "fields": {"regex": "http://vimeo.com/\\S*", "endpoint": "http://vimeo.com/api/oembed.json", "name": "Vimeo", "format": 1}}, {"pk": 16, "model": "oembed.providerrule", "fields": {"regex": "http://vids.myspace.com/.*", "endpoint": "http://vids.myspace.com/index.cfm?fuseaction=oembed", "name": "MySpace", "format": 1}}]

0 comments on commit 8ec587a

Please sign in to comment.