From 57969731b2b0829751b1586eec3349eb9fe78663 Mon Sep 17 00:00:00 2001 From: Venelin Stoykov Date: Thu, 26 Oct 2017 16:25:36 +0300 Subject: [PATCH] Fix routablepageurl to work with WAGTAIL_APPEND_SLASH = False (#3856) --- .../templatetags/wagtailroutablepage_tags.py | 2 ++ wagtail/contrib/wagtailroutablepage/tests.py | 9 +++++++++ 2 files changed, 11 insertions(+) diff --git a/wagtail/contrib/wagtailroutablepage/templatetags/wagtailroutablepage_tags.py b/wagtail/contrib/wagtailroutablepage/templatetags/wagtailroutablepage_tags.py index 3834f4e38b..8c4d3e60fd 100644 --- a/wagtail/contrib/wagtailroutablepage/templatetags/wagtailroutablepage_tags.py +++ b/wagtail/contrib/wagtailroutablepage/templatetags/wagtailroutablepage_tags.py @@ -22,4 +22,6 @@ def routablepageurl(context, page, url_name, *args, **kwargs): request = context['request'] base_url = page.relative_url(request.site) routed_url = page.reverse_subpage(url_name, args=args, kwargs=kwargs) + if not base_url.endswith('/'): + base_url += '/' return base_url + routed_url diff --git a/wagtail/contrib/wagtailroutablepage/tests.py b/wagtail/contrib/wagtailroutablepage/tests.py index bd5d48b7be..44bc095441 100644 --- a/wagtail/contrib/wagtailroutablepage/tests.py +++ b/wagtail/contrib/wagtailroutablepage/tests.py @@ -1,5 +1,6 @@ from __future__ import absolute_import, unicode_literals +import mock from django.core.urlresolvers import NoReverseMatch from django.test import RequestFactory, TestCase @@ -185,3 +186,11 @@ class TestRoutablePageTemplateTag(TestCase): 'external_view', 'joe-bloggs') self.assertEqual(url, self.routable_page.url + 'external/joe-bloggs/') + + def test_templatetag_reverse_external_view_without_append_slash(self): + with mock.patch('wagtail.wagtailcore.models.WAGTAIL_APPEND_SLASH', False): + url = routablepageurl(self.context, self.routable_page, + 'external_view', 'joe-bloggs') + expected = self.routable_page.url + '/' + 'external/joe-bloggs/' + + self.assertEqual(url, expected)