This issue has been created
 
 
XWiki Platform / cid:jira-generated-image-avatar-98d901c3-1bf1-434d-a606-6914a74b64da XWIKI-25415 Open

getUniquePageName doesn't honor the page naming strategy

 
View issue   ยท   Add comment
 

Issue created

 
cid:jira-generated-image-avatar-839ab07b-06c3-41ad-ae80-efc57e8c7371 Vincent Massol created this issue on 19/Oct/26 19:57
 
Summary: getUniquePageName doesn't honor the page naming strategy
Issue Type: cid:jira-generated-image-avatar-98d901c3-1bf1-434d-a606-6914a74b64da Bug
Affects Versions: 12.0-rc-1
Assignee: Unassigned
Components: Model - Validation, Old Core
Created: 19/Oct/26 19:57
Priority: cid:jira-generated-image-static-major-9baaca4d-f2f3-4bfd-8af8-5419c93fab38 Major
Reporter: Vincent Massol
Description:

XWiki#getUniquePageName(String space, String name, XWikiContext) (and its $xwiki.getUniquePageName() script API) always runs the given name through clearName() before checking whether it is free. clearName() predates the page naming strategies: it removes dots, spaces and other characters regardless of the strategy configured in Administration > Editing > Name Strategies. As a consequence, code that first transforms a name with the configured strategy and then asks for a unique name gets back a name that doesn't comply with that strategy.

Steps to reproduce

  • In Administration > Editing > Name Strategies, select the Kebab Case Name Strategy, enable Transform names automatically and enable the option keeping dots between digits
  • Create a blog post titled XWiki 1.2.3 Released: its page is Blog.xwiki-1.2.3-released, as expected
  • Create a second blog post with the same title

Expected result

The second post's page name is unique and still complies with the naming strategy, e.g. xwiki-1.2.3-released-1.

Actual result

The second post's page is Blog.xwiki-123-released: since xwiki-1.2.3-released already exists, the Blog application calls $xwiki.getUniquePageName(), whose clearName() call strips the dots. The resulting name only looks unique because the cleaned name happens to be free, and the version number in it is lost.

This was noticed on xwiki.org (18.4.6) when creating a release blog post whose page already existed. Any other caller of getUniquePageName() on a wiki using a naming strategy is affected the same way.

Direction

See the brainstorming at https://forum.xwiki.org/t/generating-unique-entity-references-that-honor-the-page-naming-strategy/19001 for a proposed direction: a generic unique entity reference generator honoring the naming strategy (in model-validation), backed by a generic entity existence checker (in model-api), with XWiki#getUniquePageName() deprecated and delegating to it so that existing callers get the fix without changes.

Note also that the existence check in getUniquePageName() builds the reference by string concatenation (space + "." + pageName), which is wrong for nested spaces or names containing dots once dots are no longer stripped.