In an idprovider, users are created programatically. However the username is not sanitized, so creation will fail if say you pass in an email address, because ‘@’ is an invalid character.
I think createUser should sanitize the username automatically. Either that or have a method so it can be done before calling createUser.
I guess this could be useful for content names too. In content studio it happens on the fly when you type in a displayName. I could guess what characthers are illegal, but it would be much better to use the same method that is used in Enonic XP.
Ascii and Norwegian chars would be something like this: (haven’t tested all scenarios)
exports.sanitizeName = function(name) {
return name.toLowerCase()
.replace(/[!"()]+/g, '') // ASCII removed.
.replace(/[#$%&'*+,/:;<=>?@[\\\]^_`{|}~\s]+/g, '-') // ASCII replaced.
.replace(/[æÆ]/g, 'ae').replace(/[øØ]/g, 'o').replace(/[åÅ]/g, 'a') // Norwegian chars.
.replace(/--+/g, '-') // Two or more dashes becomes just one.
.replace(/^[-.]+/, '') // Do not begin with - or .
.replace(/[-.]+$/, ''); // Do not end in - or .
};