From ee210ae5d88c5c7a59c035a25c531848d89ae9c7 Mon Sep 17 00:00:00 2001 From: Stephan Date: Thu, 24 Apr 2014 00:16:56 +0200 Subject: [PATCH] U4-3027 - fix content & property types alias casing --- src/Umbraco.Core/Models/ContentTypeBase.cs | 4 +++- src/Umbraco.Core/Models/PropertyType.cs | 3 ++- src/Umbraco.Core/Strings/CleanStringType.cs | 5 +++-- src/Umbraco.Web/WebServices/CoreStringsController.cs | 4 +++- .../umbraco/controls/ContentTypeControlNew.ascx.cs | 9 ++++++--- .../umbraco.presentation/umbraco/create/nodetypeTasks.cs | 5 ++++- 6 files changed, 21 insertions(+), 9 deletions(-) diff --git a/src/Umbraco.Core/Models/ContentTypeBase.cs b/src/Umbraco.Core/Models/ContentTypeBase.cs index 953ef5ccce..00e9c1e30c 100644 --- a/src/Umbraco.Core/Models/ContentTypeBase.cs +++ b/src/Umbraco.Core/Models/ContentTypeBase.cs @@ -6,6 +6,7 @@ using System.Linq; using System.Reflection; using System.Runtime.Serialization; using Umbraco.Core.Models.EntityBase; +using Umbraco.Core.Strings; namespace Umbraco.Core.Models { @@ -173,7 +174,8 @@ namespace Umbraco.Core.Models { SetPropertyValueAndDetectChanges(o => { - _alias = value.ToSafeAlias(); + //_alias = value.ToSafeAlias(); + _alias = value.ToCleanString(CleanStringType.Alias | CleanStringType.UmbracoCase); return _alias; }, _alias, AliasSelector); } diff --git a/src/Umbraco.Core/Models/PropertyType.cs b/src/Umbraco.Core/Models/PropertyType.cs index ddc06a5d47..d38a516911 100644 --- a/src/Umbraco.Core/Models/PropertyType.cs +++ b/src/Umbraco.Core/Models/PropertyType.cs @@ -5,6 +5,7 @@ using System.Text.RegularExpressions; using Umbraco.Core.Models.EntityBase; using Umbraco.Core.Persistence; using Umbraco.Core.PropertyEditors; +using Umbraco.Core.Strings; namespace Umbraco.Core.Models { @@ -96,7 +97,7 @@ namespace Umbraco.Core.Models { SetPropertyValueAndDetectChanges(o => { - _alias = value; + _alias = value.ToCleanString(CleanStringType.Alias | CleanStringType.UmbracoCase); return _alias; }, _alias, AliasSelector); } diff --git a/src/Umbraco.Core/Strings/CleanStringType.cs b/src/Umbraco.Core/Strings/CleanStringType.cs index 4c53be4cb8..ea9603ec6f 100644 --- a/src/Umbraco.Core/Strings/CleanStringType.cs +++ b/src/Umbraco.Core/Strings/CleanStringType.cs @@ -57,8 +57,9 @@ namespace Umbraco.Core.Strings /// /// Umbraco "safe alias" case. /// - /// This is for backward compatibility. Casing is unchanged within terms, - /// and is pascal otherwise. + /// Uppercases the first char of each term except for the first + /// char of the string, everything else including the first char of the + /// string is unchanged. UmbracoCase = 0x20, diff --git a/src/Umbraco.Web/WebServices/CoreStringsController.cs b/src/Umbraco.Web/WebServices/CoreStringsController.cs index 78eb449273..6da704a520 100644 --- a/src/Umbraco.Web/WebServices/CoreStringsController.cs +++ b/src/Umbraco.Web/WebServices/CoreStringsController.cs @@ -20,9 +20,11 @@ namespace Umbraco.Web.WebServices [HttpGet] public JsonResult ToSafeAlias(string value, bool camelCase = true) { + // always return a proper camel-cased alias + // when checking... javascript does a case-unsensitive comparison return value == null ? Json(new {error = "no value."}, JsonRequestBehavior.AllowGet) - : Json(new { alias = value.ToSafeAlias(camelCase) }, JsonRequestBehavior.AllowGet); + : Json(new { alias = value.ToCleanString(CleanStringType.Alias | CleanStringType.CamelCase) }, JsonRequestBehavior.AllowGet); } [HttpGet] diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/controls/ContentTypeControlNew.ascx.cs b/src/Umbraco.Web/umbraco.presentation/umbraco/controls/ContentTypeControlNew.ascx.cs index c02c3fa8df..7a94afced9 100644 --- a/src/Umbraco.Web/umbraco.presentation/umbraco/controls/ContentTypeControlNew.ascx.cs +++ b/src/Umbraco.Web/umbraco.presentation/umbraco/controls/ContentTypeControlNew.ascx.cs @@ -293,7 +293,7 @@ namespace umbraco.controls global::Umbraco.Web.UmbracoContext.Current = asyncState.UmbracoContext; _contentType.ContentTypeItem.Name = txtName.Text; - _contentType.ContentTypeItem.Alias = txtAlias.Text; + _contentType.ContentTypeItem.Alias = txtAlias.Text; // raw, contentType.Alias takes care of it _contentType.ContentTypeItem.Icon = tb_icon.Value; _contentType.ContentTypeItem.Description = description.Text; //_contentType.ContentTypeItem.Thumbnail = ddlThumbnails.SelectedValue; @@ -832,7 +832,9 @@ jQuery(document).ready(function() {{ refreshDropDowns(); }}); GenericProperty gpData = gp.GenricPropertyControl; if (string.IsNullOrEmpty(gpData.Name.Trim()) == false && string.IsNullOrEmpty(gpData.Alias.Trim()) == false) { - var propertyTypeAlias = gpData.Alias.ToSafeAlias(); + // when creating a property don't do anything special, propertyType.Alias will take care of it + // don't enforce camel here because the user might have changed what the CoreStringsController returned + var propertyTypeAlias = gpData.Alias; if (contentTypeItem.PropertyTypeExists(propertyTypeAlias) == false) { //Find the DataTypeDefinition that the PropertyType should be based on @@ -889,7 +891,8 @@ jQuery(document).ready(function() {{ refreshDropDowns(); }}); var propertyType = contentTypeItem.PropertyTypes.First(x => x.Alias == gpw.PropertyType.Alias); if (propertyType == null) continue; var dataTypeDefinition = ApplicationContext.Current.Services.DataTypeService.GetDataTypeDefinitionById(gpw.GenricPropertyControl.Type); - propertyType.Alias = gpw.GenricPropertyControl.Alias.ToSafeAlias(); + // when saving, respect user's casing, so do nothing here as propertyType takes care of it + propertyType.Alias = gpw.GenricPropertyControl.Alias; propertyType.Name = gpw.GenricPropertyControl.Name; propertyType.Description = gpw.GenricPropertyControl.Description; propertyType.ValidationRegExp = gpw.GenricPropertyControl.Validation; diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/create/nodetypeTasks.cs b/src/Umbraco.Web/umbraco.presentation/umbraco/create/nodetypeTasks.cs index 9c20f3b889..0b54756b74 100644 --- a/src/Umbraco.Web/umbraco.presentation/umbraco/create/nodetypeTasks.cs +++ b/src/Umbraco.Web/umbraco.presentation/umbraco/create/nodetypeTasks.cs @@ -5,6 +5,7 @@ using System.Web.Security; using Umbraco.Core; using Umbraco.Core.Configuration; using Umbraco.Core.Models; +using Umbraco.Core.Strings; using Umbraco.Web.UI; using umbraco.BusinessLogic; using umbraco.DataLayer; @@ -26,7 +27,9 @@ namespace umbraco ? new ContentType(-1) : new ContentType(ApplicationContext.Current.Services.ContentTypeService.GetContentType(parentId)); contentType.CreatorId = User.Id; - contentType.Alias = Alias.Replace("'", "''"); + // when creating a content type, enforce PascalCase + // preserve separator because contentType.Alias will re-alias it + contentType.Alias = Alias.ToCleanString(CleanStringType.Alias | CleanStringType.PascalCase, ' '); contentType.Name = Alias.Replace("'", "''"); contentType.Icon = ".sprTreeFolder";