Relative links to parent directories
kljohann opened this issue · comments
Currently links starting with ../
do not work (even if they do not leave the documentation directory). E.g., for the link on http://en.cppreference.com/w/cpp/keyword/asm, (devdocs--path-expand "../language/asm" "keyword/asm")
should return language/asm
instead of keyword/../language/asm
.
I use the following as a workaround, but there is likely a better way to fix this.
@@ -272,7 +272,14 @@ (defun devdocs--path-expand (path base)
(pcase (string-to-char path)
('?/ path)
('?# (concat (devdocs--path-file base) path))
- (_ (concat (file-name-directory base) path))))
+ (_
+ (setq base (file-name-directory base))
+ (while (string-prefix-p "../" path)
+ (unless base
+ (error "Path escapes documentation directory: %s" path))
+ (setq path (string-trim-left path (rx "../"))
+ base (file-name-directory (directory-file-name base))))
+ (concat (or base "") path))))
(defun devdocs--shr-tag-pre (dom)
Yes, I noticed this randomly at some point. Thanks for pointing out to a specific example!