Permalink
Browse files

Fix base_url set to a directory name.

With base_url='/a/b', a relative URL 'c' was resolved to '/a/c'.
Now it is resolved to '/a/b/c' if /a/b is a directory, '/a/c'
otherwise. This is most likely the expected behavior.
  • Loading branch information...
1 parent 3b769e0 commit eab2646dcc62d0988d06b6a92af122cbeb8fa292 @SimonSapin SimonSapin committed Aug 2, 2012
Showing with 5 additions and 0 deletions.
  1. +1 −0 CHANGES
  2. +4 −0 weasyprint/urls.py
View
@@ -13,6 +13,7 @@ Not released yet.
- Handling of filenames and URLs on Windows
- Unicode filenames with older version of py2cairo
+ - ``base_url`` now behaves as expected when set to a directory name.
- Make some tests more robust
View
@@ -69,6 +69,10 @@ def iri_to_uri(url):
def path2url(path):
"""Return file URL of `path`"""
path = os.path.abspath(path)
+ if os.path.isdir(path):
+ # Make sure directory names have a trailing slash.
+ # Otherwise relative URIs are resolved from the parent directory.
+ path += os.path.sep
if isinstance(path, unicode):
path = path.encode(FILESYSTEM_ENCODING)
path = pathname2url(path)

0 comments on commit eab2646

Please sign in to comment.