Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug in relURL with leading slash when baseURL includes a subdirectory #9994

Closed
jmooring opened this issue Jun 10, 2022 · 5 comments · Fixed by #10002
Closed

Bug in relURL with leading slash when baseURL includes a subdirectory #9994

jmooring opened this issue Jun 10, 2022 · 5 comments · Fixed by #10002
Assignees
Milestone

Comments

@jmooring
Copy link
Member

jmooring commented Jun 10, 2022

This is not a new issue; behavior present in v0.54.0 through v0.100.2.

config.toml

baseURL = 'https://example.org/foo/'

template

{{ $url := "/foo/bar" }}
{{ $url | relURL }}
{{ $url | absURL }}

result

/foo/foo/bar
http://localhost:1313/foo/bar

Notice that the subdirectory from baseURL is repeated when using relURL, but it is not repeated when using absURL.

This has come up a few times in the forum, usually in conjunction with menu iteration:

Note that the same differences are present when comparing relLangURL and absLangURL.

@bep
Copy link
Member

bep commented Jun 10, 2022

So, this is a bug, but not as described. It's absURL that behaves badly. The relURL behaviour may seem convienient, but how would you then construct /foo/foo/bar?

@bep bep changed the title relURL is incorrect when baseURL includes subdirectory absURL is incorrect when baseURL includes subdirectory and the input starts with that subdirectory Jun 10, 2022
@bep bep added this to the v0.101.0 milestone Jun 10, 2022
@bep bep removed the NeedsTriage label Jun 10, 2022
@bep bep changed the title absURL is incorrect when baseURL includes subdirectory and the input starts with that subdirectory relURL is incorrect when baseURL includes subdirectory and the input starts with that subdirectory Jun 13, 2022
@bep
Copy link
Member

bep commented Jun 13, 2022

So, this is a bug, but not as described. It's absURL that behaves badly. The relURL behaviour may seem convienient, but how would you then construct /foo/foo/bar?

OK, looking at the code, my conclusion above wasn't right, we:

  • Treat argument with a leading slash as host relative (or to be more precise, language root-relative)
  • Treat argument without a leading slash as relative to the baseURL.

So, given that, the example above would be:

baseURL = 'https://example.org/foo/'

{{ $url := "/foo/bar" }}
{{ $url | relURL }}
{{ $url | absURL }}

/foo/bar
http://localhost:1313/foo/bar

And

{{ $url := "foo/bar" }}
{{ $url | relURL }}
{{ $url | absURL }}

/foo/foo/bar
http://localhost:1313/foo/foo/bar

@bep bep changed the title relURL is incorrect when baseURL includes subdirectory and the input starts with that subdirectory Bugs in relURL/absURL baseURL includes a subdirectory and the input starts with that subdirectory Jun 13, 2022
@bep bep self-assigned this Jun 13, 2022
@bep bep changed the title Bugs in relURL/absURL baseURL includes a subdirectory and the input starts with that subdirectory Bugs in relURL/absURL when baseURL includes a subdirectory and the input starts with that subdirectory Jun 13, 2022
@bep bep changed the title Bugs in relURL/absURL when baseURL includes a subdirectory and the input starts with that subdirectory Bug in relURL when baseURL includes a subdirectory Jun 13, 2022
@bep bep changed the title Bug in relURL when baseURL includes a subdirectory Bug in relURL with leading slash when baseURL includes a subdirectory Jun 13, 2022
@gravis
Copy link

gravis commented Jun 22, 2022

I had a regression upgrading from hugo 0.100.2 to 0.101.0 and this seems to be the only change that would be related: relURL is now stripping the baseURL path. So if my base url is https://example.org/hugo/, <link href="{{ "/css/fontawesome.min.css" | urlize | relURL }}" rel="stylesheet"> will generate <link href="/css/fontawesome.min.css" rel="stylesheet"> instead of <link href="/hugo/css/fontawesome.min.css" rel="stylesheet"> with 0.100.2. Could that be related?

@bep
Copy link
Member

bep commented Jun 24, 2022

@gravis comments on closed issues/PRs are rarely read, please open a new issue if you feal this is an issue, but I suggest you just remove the leading "/" from your ref.

jack126guy added a commit to jack126guy/rowboat-music that referenced this issue Jul 12, 2022
These paths are intended to be relative to the base URL, not the host.
The behavior that was relied upon was apparently buggy and fixed in
Hugo 0.101.0: gohugoio/hugo#9994

The behavior without leading slashes should be as expected in both
0.101.0 and previous versions.
@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 16, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants