From e8b2b94df41f28a9c5972c54d3e81ac6f7344757 Mon Sep 17 00:00:00 2001 From: Eliot Berriot Date: Wed, 19 Dec 2018 16:45:40 +0100 Subject: [PATCH] Fixed url escaping for good ;) --- api/funkwhale_api/music/spa_views.py | 7 +++++-- api/tests/music/test_spa_views.py | 10 ++++++---- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/api/funkwhale_api/music/spa_views.py b/api/funkwhale_api/music/spa_views.py index e0ba2d950..e71612cae 100644 --- a/api/funkwhale_api/music/spa_views.py +++ b/api/funkwhale_api/music/spa_views.py @@ -1,3 +1,5 @@ +import urllib.parse + from django.conf import settings from django.urls import reverse @@ -58,6 +60,7 @@ def library_track(request, pk): "content": utils.join_url(settings.FUNKWHALE_URL, obj.listen_url), } ) + metas.append( { "tag": "link", @@ -65,7 +68,7 @@ def library_track(request, pk): "type": "application/json+oembed", "href": ( utils.join_url(settings.FUNKWHALE_URL, reverse("api:v1:oembed")) - + "?url={}&format=json".format(track_url) + + "?format=json&url={}".format(urllib.parse.quote_plus(track_url)) ), } ) @@ -124,7 +127,7 @@ def library_album(request, pk): "type": "application/json+oembed", "href": ( utils.join_url(settings.FUNKWHALE_URL, reverse("api:v1:oembed")) - + "?url={}&format=json".format(album_url) + + "?format=json&url={}".format(urllib.parse.quote_plus(album_url)) ), } ) diff --git a/api/tests/music/test_spa_views.py b/api/tests/music/test_spa_views.py index 881c5a6ab..7761e313f 100644 --- a/api/tests/music/test_spa_views.py +++ b/api/tests/music/test_spa_views.py @@ -1,3 +1,5 @@ +import urllib.parse + from django.urls import reverse from funkwhale_api.common import utils @@ -61,8 +63,8 @@ def test_library_track(spa_html, no_api_auth, client, factories, settings): "type": "application/json+oembed", "href": ( utils.join_url(settings.FUNKWHALE_URL, reverse("api:v1:oembed")) - + "?url={}&format=json".format( - utils.join_url(settings.FUNKWHALE_URL, url) + + "?format=json&url={}".format( + urllib.parse.quote_plus(utils.join_url(settings.FUNKWHALE_URL, url)) ) ), }, @@ -115,8 +117,8 @@ def test_library_album(spa_html, no_api_auth, client, factories, settings): "type": "application/json+oembed", "href": ( utils.join_url(settings.FUNKWHALE_URL, reverse("api:v1:oembed")) - + "?url={}&format=json".format( - utils.join_url(settings.FUNKWHALE_URL, url) + + "?format=json&url={}".format( + urllib.parse.quote_plus(utils.join_url(settings.FUNKWHALE_URL, url)) ) ), },