fix: don't drop a path segment when resolving "./" relative URLs

urlRel2abs() prepended an extra "." when it saw "./X", turning the
relative path into "../X" and silently moving up a directory. As a
result, raw HTML <img src="./imgs/run.png"> inside a README rendered
under /r/<repo>/<file> resolved to /r/<repo>/imgs/... instead of
/r/<repo>/<dir>/imgs/..., so the image 404'd. Markdown image syntax
went through marked-base-url and was unaffected.

Strip the leading "./" instead so the relative path concatenates
cleanly with baseUrl.

Fixes #346.
This commit is contained in:
tdurieux
2026-05-03 20:01:33 +02:00
parent d8b129c670
commit d138d487f2
2 changed files with 5 additions and 2 deletions
+4 -1
View File
@@ -39,7 +39,10 @@ function urlRel2abs(
if (url.substring(0, 2) == "//") return location.protocol + url;
else if (url.charAt(0) == "/") return baseUrl + url;
else if (url.substring(0, 2) == "./") url = "." + url;
// Strip the leading "./" so it concatenates cleanly with baseUrl. The old
// code prepended an extra "." here, which turned "./X" into "../X" and
// silently dropped one path segment — see #346.
else if (url.substring(0, 2) == "./") url = url.substring(2);
else if (/^\s*$/.test(url)) return "";
//Empty = Return nothing