Skip to content

Commit f173fca

Browse files
committed
Fixing #2109: path bug in get_asset_path and wrong documentation.
1 parent e051a1d commit f173fca

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

nikola/utils.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -986,9 +986,12 @@ def get_asset_path(path, themes, files_folders={'files': ''}, _themes_dir='theme
986986
>>> print(get_asset_path('nikola.py', ['bootstrap3', 'base'], {'nikola': ''}))
987987
/.../nikola/nikola.py
988988
989-
>>> print(get_asset_path('nikola/nikola.py', ['bootstrap3', 'base'], {'nikola':'nikola'}))
989+
>>> print(get_asset_path('nikola.py', ['bootstrap3', 'base'], {'nikola': 'nikola'}))
990990
None
991991
992+
>>> print(get_asset_path('nikola/nikola.py', ['bootstrap3', 'base'], {'nikola': 'nikola'}))
993+
/.../nikola/nikola.py
994+
992995
"""
993996
for theme_name in themes:
994997
candidate = os.path.join(
@@ -998,9 +1001,11 @@ def get_asset_path(path, themes, files_folders={'files': ''}, _themes_dir='theme
9981001
if os.path.isfile(candidate):
9991002
return candidate
10001003
for src, rel_dst in files_folders.items():
1001-
candidate = os.path.abspath(os.path.join(src, path))
1002-
if os.path.isfile(candidate):
1003-
return candidate
1004+
relpath = os.path.relpath(path, rel_dst)
1005+
if not relpath.startswith('..' + os.path.sep):
1006+
candidate = os.path.abspath(os.path.join(src, relpath))
1007+
if os.path.isfile(candidate):
1008+
return candidate
10041009

10051010
if output_dir:
10061011
candidate = os.path.join(output_dir, path)

0 commit comments

Comments
 (0)