mirror of
https://github.com/tdurieux/anonymous_github.git
synced 2026-05-15 14:38:03 +02:00
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:
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user