This issue has been created
 
 
XWiki Platform / cid:jira-generated-image-avatar-8b04aa1d-2a4d-4449-9f9d-003f557d3adb XWIKI-24993 Open

The anchor of a link to another page is dropped from the URL unless a query string is also set

 
View issue   ยท   Add comment
 

Issue created

 
cid:jira-generated-image-avatar-a038145a-c890-45f4-81f1-3a3891902982 Eleni created this issue on 15/Sep/26 16:42
 
Summary: The anchor of a link to another page is dropped from the URL unless a query string is also set
Issue Type: cid:jira-generated-image-avatar-8b04aa1d-2a4d-4449-9f9d-003f557d3adb Bug
Affects Versions: 16.5.0
Assignee: Unassigned
Components: URLs
Created: 15/Sep/26 16:42
Priority: cid:jira-generated-image-static-major-27c2f108-442e-486f-b267-2df866196ed8 Major
Reporter: Eleni
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&section=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.