Commit 55a63ed4 authored by Laurent Bachelier's avatar Laurent Bachelier

Add a trailing slash to built directory URLs

parent 5b94733f
......@@ -67,7 +67,7 @@ def build_root_url(storage):
return URL(root_url.encode('utf-8'))
def build_url(root_url, f, user = None):
def build_url(root_url, f, user=None):
"""
Build an URL for a particular file and user if provided.
root_url: URL (paste.url)
......@@ -77,4 +77,7 @@ def build_url(root_url, f, user = None):
qs = {}
if user and user.key:
qs['authkey'] = user.key
return root_url.addpath(f.path).setvar(**qs)
path = f.path
if f.isdir():
path += '/'
return root_url.addpath(path).setvar(**qs)
......@@ -8,6 +8,7 @@ from webtest import TestApp
from tempfile import mkdtemp
import shutil
import os
class BuildURLTest(TestCase):
......@@ -33,3 +34,7 @@ class BuildURLTest(TestCase):
== 'http://penguin:42/'
assert quote_url(build_url(self.root_url, self.storage.get_file('/penguin'))) \
== 'http://penguin:42/penguin'
# if it is a directory, a trailing / is added
os.mkdir(os.path.join(self.root, 'penguin'))
assert quote_url(build_url(self.root_url, self.storage.get_file('/penguin'))) \
== 'http://penguin:42/penguin/'
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment