Rename page with accidental trailing whitespace

Hi,

I’m on XWiki Debian 13.0.

I accidentally created a page with a trailing whitespace, causing the URL to end with %20.

image

When I renamed the page to remove the whitespace, the page was correctly renamed, but I still see the erroneous page in the navigation panel with the Notice “The requested page could not be found.” There’s no option to delete it as well.

image

Any idea how to resolve this? The examples are using a sandbox example, the actual page at production has a few hundred nested pages so it would be best if I do not need to recreate all the pages

Thanks for your time.

Did you check the option to create an automatic redirect when renaming the page?

Thanks for the reply, I tried checking that option as well, but it caused 3 additional duplicates in the navigation panel
image

I wasn’t suggesting you to use the automatic redirect, I was just checking if you used that when doing the rename. In any case I can reproduce so it would be nice to report an issue on https://jira.xwiki.org/projects/XWIKI/issues . From my investigation:

  • it doesn’t reproduce if the page ending with a space character is terminal
  • it doesn’t reproduce if you just create and delete the nested page ending with a space character

So it seems only the rename of a nested page is affected. In my case I used the Jetty+HSQLDB distribution and so if you reproduce on the Debian distribution (Tomcat + MySQL?) it seems to suggest that the problem is not dependent on the database or the servlet container.

Note that the rename log has some SQL warning:

Starting job of type [refactoring/rename] with identifier [refactoring/rename/1617252076360-586]
Document [Home » test renaming page] has been updated.
Updating the document parent fields from [Home » test renaming page ] to [Home » test renaming page].
SQL Warning Code: -1100, SQLState: 02000
no data
Finished job of type [refactoring/rename] with identifier [refactoring/rename/1617252076360-586]

But the warning is logged after the parent update operation, which seems to suggest that the rename operation itself was OK.

The following queries:

{{velocity}}
$services.query.hql("from XWikiSpace as space where space.name like 'test%'").execute()
$services.query.hql("where doc.space like 'test%'").execute()
{{/velocity}}

return:

[Space xwiki:test renaming page , Space xwiki:test renaming page]
[test renaming page.WebHome]

This explains the problem: the space table still has an entry for "test renaming page " which should have been removed when the page (and space) was renamed. It looks like there is a problem with the query that counts the pages from a space after a page is deleted/renamed. The count for space "test renaming page " probably included the page from the new space “test renaming page”. I’ll dig more.

The root problem is this query:

select doc.fullName from XWikiDocument doc where doc.space = 'Test '

Due to the default database collation (I think) the constraint doc.space = 'Test ' ignores trailing whitespaces. It doesn’t ignore leading whitespaces though. So the following queries:

select doc.fullName from XWikiDocument doc where doc.space = 'Test'
select doc.fullName from XWikiDocument doc where doc.space = 'Test   '

return the same results: the pages from all spaces that start with “Test” followed by any number of whitespaces. So while you can create two separate spaces “Test” and "Test " in the XWikiSpaces table, the queries performed on the XWikiDocuments table will treat those two spaces as a single one.

Related issue https://jira.xwiki.org/browse/XWIKI-11617 .

@vmassol when you close https://jira.xwiki.org/browse/XWIKI-14972 did you check if the XWikiSpace was properly cleaned up after the rename? ATM the rename operation succeeds but the XWikiSpace table is not cleanup because the query of XWIkiDocuments still finds pages (from the new space after the rename). Could this be caused by the index on the doc.space column?

<property name="space" type="string" column="XWD_WEB" length="768" index="DOC_SPACE" not-null="true" />

thanks for the work, I am on Tomcat8 + MySQL.

I have reported an issue here

does this mean if I can delete the space, the navigation panel should reflect correctly? Is there any way to do that?

The workaround for future renames is to perform the rename in two steps:

  • first rename "test " to “Xtest”
  • then rename “Xtest” to “test”

This way the "test " space will be seen as empty after the first rename and will be removed.

The fix for a broken rename is to:

  • rename “test” to “Xtest”
  • navigate to the missing "test " page and (re)created it (the content doesn’t matter)
  • delete the "test " page you just created
  • rename “Xtest” to “test”

tried this and it works

thanks!