Fix resolving of absolute URLs#96
Conversation
|
ping |
|
Sorry, for the late response! We use this because you often encounter relative URLs in READMEs that point to an image or another document online. In such cases |
@muesli But this doesn't work properly: // This is the current behaviour:
resolveURL("https://example.com/a/b", "/foo/bar") == "https://example.com/a/b/foo/bar"
// Semantically correct & proposed here:
resolveURL("https://example.com/a/b", "/foo/bar") == "https://example.com/foo/bar"
Doesn't seem like the right fit, relative things like |
|
I think there have to be Unit tests :D |
|
@6543 You're right, we should add a few tests for this function. @noerw I wonder if this isn't the correct behavior, though? The root path refers to the document's root, not the site's root. Consider the following situations, which your PR would break: |
|
@muesli some background info... it's a dependency of https://gitea.com/gitea/tea/pulls/332 (currently fixed by |
Will add some tests later some github.com markdown testing (
|
|
Ok, treating subpaths as belonging to the base-namespace, as it would seem useful for github et al, is a special case deviating from the URI spec. As this lib is not specific to git-forge content, following the spec seems appropriate. base := strings.TrimRight(repoURL, "/") + "/" # ensure trailing slash
href = strings.TrimLeft(href, "/") # ensure relative pathLooking at how github and gitea webfrontends (which we can treat as reference implementation for this usecase) render such URLs in markdown, it shows gitea handles repo path specially, and github plain follows URL spec So i'd say this PR actually implements the right thing ;) |
|
This still seems to break resolving URLs with various markdown links on GitHub. I'll add an example to the tests, so we can work on the implemenation from there. |
|
I won't follow up on this; in |
~~this is semi-blocked by charmbracelet/glamour#96, but behaviour isn't really worse than the previous behaviour (most links work, some are still broken)~~ #### testcase for link resolver ``` tea pr 332 tea checkout 332 && make install && tea pr 332 ``` - [rel](./332) - [abs](/gitea/tea/pulls/332) - [full](https://gitea.com/gitea/tea/pulls/332) Co-authored-by: Norwin Roosen <git@nroo.de> Co-authored-by: 6543 <6543@obermui.de> Reviewed-on: https://gitea.com/gitea/tea/pulls/332 Reviewed-by: 6543 <6543@obermui.de> Reviewed-by: Andrew Thornton <art27@cantab.net> Co-authored-by: Norwin <noerw@noreply.gitea.io> Co-committed-by: Norwin <noerw@noreply.gitea.io>
URL resolver treats all URLs as path-relative, even path-absolute ones like
/π€The thing is, that
resolveRelativeURL()is not only used for relative URLs.This means, a link with a path-absolute URL like
/foo/bar.jpgwould be resolved as relative.I'm not sure what the check for a leading
/was meant for, this was in the repo from the first commit on (in a different variant having the same issue)..