Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
assert join_path('a@b', 'c') == 'a@b/c'
assert join_path('a@b', '') == 'a@b'
assert join_path('a@b', '@c') == 'a@c'
assert join_path('a@b/c', 'a@b') == 'a/a@b'
assert join_path('blog@archive', '2015') == 'blog@archive/2015'
assert join_path('blog@archive/2015', '..') == 'blog@archive'
assert join_path('blog@archive/2015', '@archive') == 'blog@archive'
assert join_path('blog@archive', '..') == 'blog'
assert join_path('blog@archive', '.') == 'blog@archive'
assert join_path('blog@archive', '') == 'blog@archive'
# special behavior: parent of pagination paths is always the actual
# page parent.
assert join_path('/blog@1', '..') == '/'
assert join_path('/blog@2', '..') == '/'
# But joins on the same level keep the path
assert join_path('/blog@1', '.') == '/blog@1'
assert join_path('/blog@2', '.') == '/blog@2'
assert join_path('/blog@1', '') == '/blog@1'
assert join_path('/blog@2', '') == '/blog@2'
def test_join_path():
from lektor.utils import join_path
assert join_path('a', 'b') == 'a/b'
assert join_path('/a', 'b') == '/a/b'
assert join_path('a@b', 'c') == 'a@b/c'
assert join_path('a@b', '') == 'a@b'
assert join_path('a@b', '@c') == 'a@c'
assert join_path('a@b/c', 'a@b') == 'a/a@b'
assert join_path('blog@archive', '2015') == 'blog@archive/2015'
assert join_path('blog@archive/2015', '..') == 'blog@archive'
assert join_path('blog@archive/2015', '@archive') == 'blog@archive'
assert join_path('blog@archive', '..') == 'blog'
assert join_path('blog@archive', '.') == 'blog@archive'
assert join_path('blog@archive', '') == 'blog@archive'
# special behavior: parent of pagination paths is always the actual
# page parent.
assert join_path('/blog@1', '..') == '/'
assert join_path('/blog@2', '..') == '/'
# But joins on the same level keep the path
assert join_path('/blog@1', '.') == '/blog@1'
assert join_path('/blog@2', '.') == '/blog@2'
def test_join_path():
from lektor.utils import join_path
assert join_path('a', 'b') == 'a/b'
assert join_path('/a', 'b') == '/a/b'
assert join_path('a@b', 'c') == 'a@b/c'
assert join_path('a@b', '') == 'a@b'
assert join_path('a@b', '@c') == 'a@c'
assert join_path('a@b/c', 'a@b') == 'a/a@b'
assert join_path('blog@archive', '2015') == 'blog@archive/2015'
assert join_path('blog@archive/2015', '..') == 'blog@archive'
assert join_path('blog@archive/2015', '@archive') == 'blog@archive'
assert join_path('blog@archive', '..') == 'blog'
assert join_path('blog@archive', '.') == 'blog@archive'
assert join_path('blog@archive', '') == 'blog@archive'
# special behavior: parent of pagination paths is always the actual
# page parent.
assert join_path('/blog@1', '..') == '/'
assert join_path('/blog@2', '..') == '/'
assert join_path('blog@archive/2015', '..') == 'blog@archive'
assert join_path('blog@archive/2015', '@archive') == 'blog@archive'
assert join_path('blog@archive', '..') == 'blog'
assert join_path('blog@archive', '.') == 'blog@archive'
assert join_path('blog@archive', '') == 'blog@archive'
# special behavior: parent of pagination paths is always the actual
# page parent.
assert join_path('/blog@1', '..') == '/'
assert join_path('/blog@2', '..') == '/'
# But joins on the same level keep the path
assert join_path('/blog@1', '.') == '/blog@1'
assert join_path('/blog@2', '.') == '/blog@2'
assert join_path('/blog@1', '') == '/blog@1'
assert join_path('/blog@2', '') == '/blog@2'
assert join_path('blog@archive', '2015') == 'blog@archive/2015'
assert join_path('blog@archive/2015', '..') == 'blog@archive'
assert join_path('blog@archive/2015', '@archive') == 'blog@archive'
assert join_path('blog@archive', '..') == 'blog'
assert join_path('blog@archive', '.') == 'blog@archive'
assert join_path('blog@archive', '') == 'blog@archive'
# special behavior: parent of pagination paths is always the actual
# page parent.
assert join_path('/blog@1', '..') == '/'
assert join_path('/blog@2', '..') == '/'
# But joins on the same level keep the path
assert join_path('/blog@1', '.') == '/blog@1'
assert join_path('/blog@2', '.') == '/blog@2'
assert join_path('/blog@1', '') == '/blog@1'
assert join_path('/blog@2', '') == '/blog@2'
def test_join_path():
from lektor.utils import join_path
assert join_path('a', 'b') == 'a/b'
assert join_path('/a', 'b') == '/a/b'
assert join_path('a@b', 'c') == 'a@b/c'
assert join_path('a@b', '') == 'a@b'
assert join_path('a@b', '@c') == 'a@c'
assert join_path('a@b/c', 'a@b') == 'a/a@b'
assert join_path('blog@archive', '2015') == 'blog@archive/2015'
assert join_path('blog@archive/2015', '..') == 'blog@archive'
assert join_path('blog@archive/2015', '@archive') == 'blog@archive'
assert join_path('blog@archive', '..') == 'blog'
assert join_path('blog@archive', '.') == 'blog@archive'
assert join_path('blog@archive', '') == 'blog@archive'
# special behavior: parent of pagination paths is always the actual
# page parent.
assert join_path('/blog@1', '..') == '/'
assert join_path('/blog@2', '..') == '/'
# But joins on the same level keep the path
assert join_path('/blog@1', '.') == '/blog@1'
assert join_path('/blog@2', '.') == '/blog@2'
assert join_path('/blog@1', '') == '/blog@1'
assert join_path('/blog@2', '') == '/blog@2'
def test_join_path():
from lektor.utils import join_path
assert join_path('a', 'b') == 'a/b'
assert join_path('/a', 'b') == '/a/b'
assert join_path('a@b', 'c') == 'a@b/c'
assert join_path('a@b', '') == 'a@b'
assert join_path('a@b', '@c') == 'a@c'
assert join_path('a@b/c', 'a@b') == 'a/a@b'
assert join_path('blog@archive', '2015') == 'blog@archive/2015'
assert join_path('blog@archive/2015', '..') == 'blog@archive'
assert join_path('blog@archive/2015', '@archive') == 'blog@archive'
assert join_path('blog@archive', '..') == 'blog'
assert join_path('blog@archive', '.') == 'blog@archive'
assert join_path('blog@archive', '') == 'blog@archive'
# special behavior: parent of pagination paths is always the actual
# page parent.
assert join_path('/blog@1', '..') == '/'
assert join_path('/blog@2', '..') == '/'
# But joins on the same level keep the path
assert join_path('/blog@1', '.') == '/blog@1'
assert join_path('/blog@2', '.') == '/blog@2'
assert join_path('/blog@1', '') == '/blog@1'
assert join_path('/blog@2', '') == '/blog@2'
def test_join_path():
from lektor.utils import join_path
assert join_path('a', 'b') == 'a/b'
assert join_path('/a', 'b') == '/a/b'
assert join_path('a@b', 'c') == 'a@b/c'
assert join_path('a@b', '') == 'a@b'
assert join_path('a@b', '@c') == 'a@c'
assert join_path('a@b/c', 'a@b') == 'a/a@b'
assert join_path('blog@archive', '2015') == 'blog@archive/2015'
assert join_path('blog@archive/2015', '..') == 'blog@archive'
assert join_path('blog@archive/2015', '@archive') == 'blog@archive'
assert join_path('blog@archive', '..') == 'blog'
assert join_path('blog@archive', '.') == 'blog@archive'
assert join_path('blog@archive', '') == 'blog@archive'
# special behavior: parent of pagination paths is always the actual
# page parent.
assert join_path('/blog@1', '..') == '/'
assert join_path('/blog@2', '..') == '/'
# But joins on the same level keep the path
assert join_path('/blog@1', '.') == '/blog@1'
assert join_path('blog@archive', '2015') == 'blog@archive/2015'
assert join_path('blog@archive/2015', '..') == 'blog@archive'
assert join_path('blog@archive/2015', '@archive') == 'blog@archive'
assert join_path('blog@archive', '..') == 'blog'
assert join_path('blog@archive', '.') == 'blog@archive'
assert join_path('blog@archive', '') == 'blog@archive'
# special behavior: parent of pagination paths is always the actual
# page parent.
assert join_path('/blog@1', '..') == '/'
assert join_path('/blog@2', '..') == '/'
# But joins on the same level keep the path
assert join_path('/blog@1', '.') == '/blog@1'
assert join_path('/blog@2', '.') == '/blog@2'
assert join_path('/blog@1', '') == '/blog@1'
assert join_path('/blog@2', '') == '/blog@2'
alt = self.alt
resolve = True
path = getattr(path, 'url_path', path)
if path[:1] == '!':
resolve = False
path = path[1:]
if resolve:
if not path.startswith('/'):
if self.path is None:
raise RuntimeError('Cannot use relative URL generation '
'from sources that do not have a '
'path. The source object without '
'a path is %r' % self)
path = join_path(self.path, path)
source = self.pad.get(path, alt=alt)
if source is not None:
path = source.url_path
else:
path = posixpath.join(self.url_path, path)
if absolute:
return path
if base_url is None:
base_url = self.url_path
return self.pad.make_url(path, base_url, absolute, external)