11

While installing a content package from my production environment (Sitecore 8.1) into my development environment (Sitecore 8.2), I'm seeing this error message in my Sitecore log:

ManagedPoolThread #2 11:07:07 ERROR Error installing items/master/sitecore/content/Content Source/people/2014/10/22/12/58/lütz-alexandra/{AC7C6913-A1C7-479E-9B61-C9F247026699}/en/1/xml Exception: Sitecore.Exceptions.InvalidItemNameException Message: An item name must satisfy the pattern: ^[\w*\$][\w\s-\$]*((\d{1,})){0,1}$ (controlled by the setting ItemNameValidation) Source: Sitecore.Kernel at Sitecore.Data.Items.ItemUtil.AssertItemName(Item destinationItem, String name) at Sitecore.Data.Items.Item.set_Name(String value)
at Sitecore.Install.Items.ItemInstaller.VersionInstaller.InstallVersion(Item version) at Sitecore.Install.Items.ItemInstaller.VersionInstaller.PasteVersion(XmlNode versionXml, Item target, VersionInstallMode mode, IProcessingContext context, Boolean removeOtherVersions) at Sitecore.Install.Items.ItemInstaller.InstallEntry(PackageEntry entry)

I believe that this message is coming from the fact that my item name has a European character in it's item name (ü). I've looked into my sitecore.config file and found this value for the ItemNameValidation setting:

<!--  ITEM NAME VALIDATION
        Regular expression for validating item names
  -->
<setting name="ItemNameValidation" value="^[\w\*\$][\w\s\-\$]*(\(\d{1,}\)){0,1}$" />

From what I can tell, the \w should be allow that character to be valid, but I have a suspicion that it's not working that way. I'm thinking that I need to include \p{L} embedded into the regex somewhere to support international characters. I can't help thinking that since Sitecore is developed in a European country, that they would support European character sets out of the box. Any ideas on how to correct this error?

  • Does the ItemNameValidation setting match between your local environment and the settings you have on your PROD instance? – jammykam Oct 4 '16 at 18:18
  • Yes, the settings are identical. However, these content was imported from a Sitecore 7.2 instance, so maybe somehow that name got in there from a previous version of Sitecore and now it's just showing up as I'm trying to import it. – Keith VanderVeen Oct 4 '16 at 19:51
12

That exception originates from Sitecore.Data.Items.ItemUtil.GetItemNameError(string name) method in Sitecore.Kernel:

if (itemNameValidation.Length > 0 && !Regex.IsMatch(name, itemNameValidation, RegexOptions.ECMAScript))
  return string.Format(Translate.Text("An item name must satisfy the pattern: {0} (controlled by the setting ItemNameValidation)"), (object) itemNameValidation);

A quick and dirty test shows that the item name /sitecore/content/Content Source/people/2014/10/22/12/58/lütz-alexandra should pass this validation. The following unit test passes when run:

    [Test]
    public void TestEuropeanName()
    {
        string itemName = "/sitecore/content/Content Source/people/2014/10/22/12/58/lütz-alexandra/";
        string regex = @"^[\w\*\$][\w\s\-\$]*(\(\d{1,}\)){0,1}$";

        Assert.IsTrue(itemName.Length > 0 && 
            !Regex.IsMatch(itemName, regex, RegexOptions.ECMAScript), "Item name fails regex test!");

    }

However, the item name I used was from your original question, where the actual name being used is the name in the items/master/sitecore/content/Content Source/people/2014/10/22/12/58/lütz-alexandra/{AC7C6913-A1C7-479E-9B61-C9F247026699}/en/1/xml file in your package. Check the name attribute on the item element in that XML file to see what the actual name Sitecore is trying to use.

If all else fails (or if you don't want to bother with the above), you can set the ItemNameValidation field to an empty string, install your package, then restore the ItemNameValidation field's original value.

| improve this answer | |
  • 1
    I temporarily changed my regex value to ^[\w\p{L}\*\$][\w\p{L}\s\-\$]*(\(\d{1,}\)){0,1}$, and was able to successfully import the file. In looking at the actual name in the XML file, I see that it is: lütz-alexandra. Running that through your code also passed the unit test. I'm not sure why the package installer failed on that item, but I was able to get past the error with your help. – Keith VanderVeen Oct 4 '16 at 19:50
2

The right way to solve this, is to correct the name of the item causing the problem.

To install the package, you can temporarily patch the value of the ItemNameValidation setting to ".*" to allow for any character in the item name.

After installing, I would suggest that you remove the config patch to change the setting back to the original, and prevent editors from creating items with invalid item names.

| improve this answer | |
2

To add to the already good answer by Ed, the regex check in GetItemNameError is a little different in Sitecore 7.2: if (itemNameValidation.Length > 0 && !Regex.IsMatch(name, itemNameValidation)).

Note the lack of RegexOptions.ECMAScript, which changes the meaning of \w to exclude characters with diacritics. That explains why items from a Sitecore 7.2 instance sometimes can't be imported into Sitecore 8 or higher instance (see Keith's comment on his question).

I haven't tested this, but maybe you can get around this by serializing the item and deserializing it in the new version.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.