Username cannot contain a dot

I’m working on a migration form an old wiki system to xwiki.
In xwiki a username cannot contain a dot.
But in the wiki system that I try to migrate, there are some usernames containing a dot.

Is there a reason xwiki doesn’t let a user using a dot in the username?
Is there a way to disable this restriction?

Thanks for your help :slight_smile:

See Loading.... It used to be a technical limitation with page names (user ids are page names) which should be mostly resolved now. The only potential remaining problem is lazy code assuming that a user id never contains a dot since it’s been like this for a very long time.

The check is currently located in xwiki-platform/xwiki-platform-core/xwiki-platform-oldcore/src/main/java/com/xpn/xwiki/XWiki.java at master · xwiki/xwiki-platform · GitHub but the code suggests that you can change the user name validation regex through the property xwiki.validusername in xwiki.cfg file. Could be interesting to try that and report on Loading... if you don’t notice any problem after a while so that we change the default.

which regex library are you guys using? I tried the following regex, which works in an online validator but I’m getting an MalFormedPerl5PatternException:
^[a-zA-Z0-9_\-\.]+$

Invalid regular expression for xwiki.validusername
org.apache.oro.text.perl.MalformedPerl5PatternException: Invalid expression: ^[a-zA-Z0-9_\-\.]+$
at org.apache.oro.text.perl.Perl5Util.__parseMatchExpression(Unknown Source)
at org.apache.oro.text.perl.Perl5Util.match(Unknown Source)
at org.apache.oro.text.perl.Perl5Util.match(Unknown Source)
at com.xpn.xwiki.util.Util.match(Util.java:97)
at com.xpn.xwiki.XWiki.createUser(XWiki.java:3921)
at com.xpn.xwiki.api.XWiki.createUser(XWiki.java:1538)
at com.xpn.xwiki.api.XWiki.createUser(XWiki.java:1502)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)

Hmm no idea why this code uses Perl5Util, it’s not like XWiki was older than standard Java Pattern. Should probably be changed.

To answer your question the name seems to suggest you should use perl regex syntax. The exact library seems to be Jakarta ORO - Jakarta ORO and the first line in that website comfort me in the idea to get rid of this…

Thanks for your help, the following regex worked for me :slight_smile:

/^[a-zA-Z0-9_\.\-]+$/

So I’m able to create a user containing a dot now.
But I can’t login with that user.
Is there a different regex check somewhere else?

So I think I figured out why it is not working.
I’m able to login if the username contains a dash but not if it contains a dot.
I think the problem is that dot’s are used to separate spaces from pages in the xwiki API.
I think the following code explains it:

String username = convertUsername(request.getParameter(“xwikiname”), context);
if (username.indexOf(‘.’) == -1) {
username = “XWiki.” + username;
}
XWikiDocument userDocument = getDocument(username, context);

So if my username is user.name wiki searches for a page name in the space XWiki.user instead for a
page user.name in the space XWiki.

Could that be the problem?

I don’t know if it’s the only problem but yes you did guess right. That’s part of the “lazy code assuming that a user id never contains a dot since it’s been like this for a very long time” I was referring to.

There is actually two problems here:

  • the code assume that if there is a dot then it’s a complete reference and not a user id
  • concatenation is a very bad way to create a reference from escaping point of view, it should user something like new LocalDocumentReference("XWiki", username) to pass to getDocument.

If you feel like working on this a possibility which should be safe from retro compatibility point of view would be to keep the current code but if userDocument.isNew() is true (meaning the document does not exist) then also try in the “XWiki” space (if it’s not what we already tried of course).