Strange behaviour of canonifyURLs when baseURL contains subdirectory matching a content section

Hello,

I am using

hugo v0.159.1+extended+withdeploy linux/amd64 BuildDate=unknown

and have a project with leaf bundles in

content/test/<bundle>

With hugo.toml:

baseURL = "https://www.example.com/test/"
relativeURLs = false
canonifyURLs = false

I get the following link to a bundle in my output:

href=“/test/test/<bundle>/”

just as expected and working.

However, with hugo.toml:

baseURL = "https://www.example.com/test/"
relativeURLs = false
canonifyURLs = true

I get this link to a bundle in my output:

href=“https://www.example.com/test/<bundle>/”

So one test has been omitted and the link is not working.

Now with hugo.toml:

baseURL = "https://www.example.com/subdir/"
relativeURLs = false
canonifyURLs = true

I get this link to a bundle in my output:

href=“https://www.example.com/subdir/test/<bundle>/”

as expected and working.

Then I tried hugo.toml:

baseURL = "https://www.example.com/test/test/"
relativeURLs = false
canonifyURLs = true

and got

href=“https://www.example.com/test/test/test/<bundle>/”

again as expected and working.

I can’t imagine that this is intended behaviour and would like to hear your comments or if I am missing something. Thanks.

Before digging into this, why are you enabling this option?

https://gohugo.io/content-management/urls/#canonical-urls

This is a legacy configuration option, superseded by template functions and Markdown render hooks, and will likely be removed in a future release.

I guess I missed the deprecation notice. Also, I wasn’t sure if the code that produces this behaviour would be used in other functions.

Given that no one should be using the canonifyURLs option at this point, I don’t think we should log a bug on this.