Skip to content

Commit 88bcf86

Browse files
committedJan 7, 2018
Avoid broken links when links are not as expected.
1 parent 68ced32 commit 88bcf86

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed
 

‎nikola/plugins/command/check.py

+20-4
Original file line numberDiff line numberDiff line change
@@ -328,16 +328,32 @@ def analyze(self, fname, find_sources=False, check_remote=False):
328328
os.path.join(os.path.dirname(filename).encode('utf-8'), unquoted_target))
329329

330330
elif url_type in ('full_path', 'absolute'):
331+
relative = False
331332
if url_type == 'absolute':
332333
# convert to 'full_path' case, ie url relative to root
333-
url_rel_path = parsed.path[len(url_netloc_to_root):]
334+
if parsed.path.startswith(url_netloc_to_root):
335+
url_rel_path = parsed.path[len(url_netloc_to_root):]
336+
else:
337+
url_rel_path = parsed.path
338+
if not url_rel_path.startswith('/'):
339+
relative = True
334340
else:
335341
# convert to relative to base path
336-
url_rel_path = target[len(url_netloc_to_root):]
342+
if target.startswith(url_netloc_to_root):
343+
url_rel_path = target[len(url_netloc_to_root):]
344+
else:
345+
url_rel_path = target
346+
if not url_rel_path.startswith('/'):
347+
relative = True
337348
if url_rel_path == '' or url_rel_path.endswith('/'):
338349
url_rel_path = urljoin(url_rel_path, self.site.config['INDEX_FILE'])
339-
fs_rel_path = fs_relpath_from_url_path(url_rel_path)
340-
target_filename = os.path.join(self.site.config['OUTPUT_FOLDER'], fs_rel_path)
350+
if relative:
351+
unquoted_target = unquote(target).encode('utf-8')
352+
target_filename = os.path.abspath(
353+
os.path.join(os.path.dirname(filename).encode('utf-8'), unquoted_target))
354+
else:
355+
fs_rel_path = fs_relpath_from_url_path(url_rel_path)
356+
target_filename = os.path.join(self.site.config['OUTPUT_FOLDER'], fs_rel_path)
341357

342358
if any(re.search(x, target_filename) for x in self.whitelist):
343359
continue

0 commit comments

Comments
 (0)
Please sign in to comment.