Details
-
Bug
-
Resolution: Unresolved
-
Major
-
None
-
18.7.0
-
None
-
Unknown
-
Description
When you create a link to a specific section (anchor) on another page, the anchor is silently dropped. The link works and looks normal, but it always opens the target page at the top instead of jumping to the section.
How to reproduce
1. Create a link like this:
[[label>>doc:Sandbox.MyPage||anchor="HTest"]]
(https://www.xwiki.org/xwiki/bin/view/Documentation/UserGuide/Features/XWikiSyntax/?syntax=2.1§ion=Links)
Expected: link goes to
.../MyPage#HTest
Actual: link goes to
.../MyPage (anchor missing)
Workaround that "shouldn't" be needed but reveals the cause
If you add any query string parameter alongside the anchor, it suddenly works:
[[label>>doc:Sandbox.MyPage||anchor="HTest" queryString="a=1"]]
->
.../MyPage?a=1#HTest
(correct)
This shows the bug isn't in how the link is rendered, it's in the underlying
$xwiki.getURL()
function, which only keeps the anchor when a query string is also passed. You can confirm this directly without any link markup at all:
{{velocity}}
$xwiki.getURL('Sandbox.WebHome', 'view', '', 'HTest')
{{/velocity}}
This returns a URL with no #HTest, even though HTest was explicitly passed as the anchor.
Note: There's no visual warning, the link stays blue and "valid." Anyone linking to a section of a FAQ, glossary, or reference page (a very common pattern) will silently get a broken jump-link, and won't know why.