From 83e6a551febb9aa55ba074a5f14a4928264f4172 Mon Sep 17 00:00:00 2001 From: Mitchel Cabuloy Date: Fri, 8 Sep 2017 04:14:56 +0800 Subject: [PATCH] Fix OEmbed endpoints --- CHANGELOG.txt | 1 + docs/releases/1.12.2.rst | 1 + wagtail/wagtailembeds/finders/oembed.py | 5 +++-- wagtail/wagtailembeds/tests.py | 11 +++++++++++ 4 files changed, 16 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 06cb1e44e..71e7ffcb9 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -21,6 +21,7 @@ Changelog * Fix: Migration for addition of `Page.draft_title` field is now reversible (Venelin Stoykov) * Fix: Fixed failure on application startup when `ManifestStaticFilesStorage` is in use and `collectstatic` has not yet been run (Matt Westcott) + * Fix: Fixed handling of Vimeo and other oEmbed providers with a format parameter in the endpoint URL (Mitchel Cabuloy) 1.12.1 (30.08.2017) diff --git a/docs/releases/1.12.2.rst b/docs/releases/1.12.2.rst index d8d1b4d0d..99ad80784 100644 --- a/docs/releases/1.12.2.rst +++ b/docs/releases/1.12.2.rst @@ -15,3 +15,4 @@ Bug fixes * Migration for addition of ``Page.draft_title`` field is now reversible (Venelin Stoykov) * Fixed failure on application startup when ``ManifestStaticFilesStorage`` is in use and ``collectstatic`` has not yet been run (Matt Westcott) + * Fixed handling of Vimeo and other oEmbed providers with a format parameter in the endpoint URL (Mitchel Cabuloy) diff --git a/wagtail/wagtailembeds/finders/oembed.py b/wagtail/wagtailembeds/finders/oembed.py index 544487b89..f85a796f0 100644 --- a/wagtail/wagtailembeds/finders/oembed.py +++ b/wagtail/wagtailembeds/finders/oembed.py @@ -26,11 +26,12 @@ class OEmbedFinder(EmbedFinder): for provider in providers or all_providers: patterns = [] + endpoint = provider['endpoint'].replace('{format}', 'json') + for url in provider['urls']: - url = url.replace('{format}', 'json') patterns.append(re.compile(url)) - self._endpoints[provider['endpoint']] = patterns + self._endpoints[endpoint] = patterns if options: self.options = self.options.copy() diff --git a/wagtail/wagtailembeds/tests.py b/wagtail/wagtailembeds/tests.py index 223588f1e..602d7d4f1 100644 --- a/wagtail/wagtailembeds/tests.py +++ b/wagtail/wagtailembeds/tests.py @@ -447,6 +447,17 @@ class TestOembed(TestCase): finder = OEmbedFinder(providers=[oembed_providers.twitter]) self.assertFalse(finder.accept("http://www.youtube.com/watch/")) + @patch('django.utils.six.moves.urllib.request.urlopen') + @patch('json.loads') + def test_endpoint_with_format_param(self, loads, urlopen): + urlopen.return_value = self.dummy_response + loads.return_value = {'type': 'video', + 'url': 'http://www.example.com'} + result = OEmbedFinder().find_embed("https://vimeo.com/217403396") + self.assertEqual(result['type'], 'video') + request = urlopen.call_args[0][0] + self.assertEqual(request.full_url.split('?')[0], "http://www.vimeo.com/api/oembed.json") + class TestEmbedTag(TestCase): @patch('wagtail.wagtailembeds.embeds.get_embed')