From da690dfc37ee516195b71f849f054354317e07f1 Mon Sep 17 00:00:00 2001 From: Kyle Fuller Date: Mon, 9 Dec 2013 18:09:34 +0000 Subject: [PATCH] Python-Markdown quote's URL's, we need to unquote to use on filesystem Fixes #1143 Closes #1095 Closes #1149 --- pelican/contents.py | 7 +++++++ pelican/tests/test_contents.py | 23 +++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/pelican/contents.py b/pelican/contents.py index 6fb55782..51ef8a22 100644 --- a/pelican/contents.py +++ b/pelican/contents.py @@ -1,6 +1,7 @@ # -*- coding: utf-8 -*- from __future__ import unicode_literals, print_function import six +from six.moves.urllib.parse import unquote import copy import locale @@ -215,6 +216,12 @@ class Content(object): os.path.join(self.relative_dir, path) ) + if path not in self._context['filenames']: + unquoted_path = path.replace('%20', ' ') + + if unquoted_path in self._context['filenames']: + path = unquoted_path + if path in self._context['filenames']: origin = '/'.join((siteurl, self._context['filenames'][path].url)) diff --git a/pelican/tests/test_contents.py b/pelican/tests/test_contents.py index 92e61355..5a9ff581 100644 --- a/pelican/tests/test_contents.py +++ b/pelican/tests/test_contents.py @@ -323,6 +323,29 @@ class TestPage(unittest.TestCase): '
blah blah
' ) + def test_intrasite_link_markdown_spaces(self): + # Markdown introduces %20 instead of spaces, this tests that + # we support markdown doing this. + cls_name = '_DummyArticle' if six.PY3 else b'_DummyArticle' + article = type(cls_name, (object,), {'url': 'article-spaces.html'}) + + args = self.page_kwargs.copy() + args['settings'] = get_settings() + args['source_path'] = 'content' + args['context']['filenames'] = {'article spaces.rst': article} + + # An intrasite link via filename with %20 as a space + args['content'] = ( + 'A simple test, with a ' + 'link' + ) + content = Page(**args).get_content('http://notmyidea.org') + self.assertEqual( + content, + 'A simple test, with a ' + 'link' + ) + class TestArticle(TestPage): def test_template(self):