Sitecore / Sitecore.Rocks

Sitecore Rocks is a plugin for Visual Studio for Sitecore developers.
Other
75 stars 27 forks source link

Data Template Bypass ItemNameValidation during Save #112

Open Zephyr-Koo opened 5 years ago

Zephyr-Koo commented 5 years ago

Tools

Context

Field names in data template (default inherited from Template) was able to save invalid string with respect of ItemNameValidation regex (i.e. ^[\w\*\$][\w\s\-\$]*(\(\d{1,}\)){0,1}$) in Sitecore.config.

Steps to reproduce

  1. Navigate to sitecore/templates/Sample which was created from Sitecore default installation
  2. Right click the template folder (i.e. Sample) and select New Template...
  3. Give it a name (e.g. NewTemplate) and proceed by clicking OK
  4. Fill the template with 1 section and 3 fields (Single-Line Text) 4.1 Section
    • MenuItem3
    • MenuItem3.1
    • MenuItemName3.1
  5. Save it (Ctrl + S)

Current result

No error was observed in Sitecore Rocks and template was saved successfully. However error message will be prompted when re-save the template without modification in Content Editor (login as admin).

Sitecore Rocks | Template saved
SitecoreRocks_Ok

Content Editor | Error on save
ContentEditor_Error

Expected result

The behavior should be consistent with Content Editor whereby invalid field name should prevent save action.

Observation

Validation enforced by Content Editor can be found @ Sitecore.Data.Items.ItemUtil.GetItemNameError

Code snippet to demonstrate validation:-

var regex = @"^[\w\*\$][\w\s\-\$]*(\(\d{1,}\)){0,1}$";

foreach (var str in new string []
{
    "MenuItem3",      // PASS
    "MenuItem3.1",    // FAILED
    "MenuItemName3.1" // FAILED
})
{
    Console.WriteLine(
        Regex.IsMatch(str, regex, RegexOptions.ECMAScript) ?
        "PASS" : "FAILED");
}
nickwesselman commented 5 years ago

Confirmed as an issue, thanks for reporting @Zephyr-Koo.