Details
-
Bug
-
Resolution: Unresolved
-
Major
-
None
-
12.0-rc-1
-
None
-
Unknown
-
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.
Attachments
Issue Links
- relates to
-
XWIKI-22062 Add option to apply entity name strategy to attachments
-
- Open
-
-
XWIKI-8666 Let getUniquePageName deal with whitespaces in document names
-
- Open
-
-
XWIKI-16861 Define name cleanup strategies and prevent creation of pages with "/" and "\" in the name by default
-
- Closed
-
- links to