U4-3027 - fix content & property types alias casing

This commit is contained in:
Stephan
2014-04-24 00:10:50 +02:00
parent 6d50b46bd8
commit f46811ff67
6 changed files with 22 additions and 9 deletions

View File

@@ -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);
}

View File

@@ -4,6 +4,7 @@ using System.Runtime.Serialization;
using System.Text.RegularExpressions;
using Umbraco.Core.Models.EntityBase;
using Umbraco.Core.Persistence.Mappers;
using Umbraco.Core.Strings;
namespace Umbraco.Core.Models
{
@@ -94,7 +95,7 @@ namespace Umbraco.Core.Models
{
SetPropertyValueAndDetectChanges(o =>
{
_alias = value;
_alias = value.ToCleanString(CleanStringType.Alias | CleanStringType.UmbracoCase);
return _alias;
}, _alias, AliasSelector);
}

View File

@@ -57,8 +57,9 @@ namespace Umbraco.Core.Strings
/// <summary>
/// Umbraco "safe alias" case.
/// </summary>
/// <remarks>This is for backward compatibility. Casing is unchanged within terms,
/// and is pascal otherwise.</remarks>
/// <remarks>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.</remarks>
UmbracoCase = 0x20,

View File

@@ -20,9 +20,11 @@ namespace Umbraco.Web.WebServices
[HttpGet]
public JsonResult ToSafeAlias(string value)
{
// 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() }, JsonRequestBehavior.AllowGet);
: Json(new { alias = value.ToCleanString(CleanStringType.Alias | CleanStringType.CamelCase) }, JsonRequestBehavior.AllowGet);
}
[HttpGet]

View File

@@ -17,6 +17,7 @@ using ClientDependency.Core;
using Umbraco.Core;
using Umbraco.Core.Logging;
using Umbraco.Core.Models;
using Umbraco.Core.Strings;
using Umbraco.Web.UI.Controls;
using umbraco.BusinessLogic;
using umbraco.cms.businesslogic;
@@ -294,7 +295,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 = ddlIcons.SelectedValue;
_contentType.ContentTypeItem.Description = description.Text;
_contentType.ContentTypeItem.Thumbnail = ddlThumbnails.SelectedValue;
@@ -834,7 +835,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
@@ -891,7 +894,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;

View File

@@ -5,6 +5,7 @@ using System.Web.Security;
using Umbraco.Core;
using Umbraco.Core.Models;
using umbraco.BusinessLogic;
using Umbraco.Core.Strings;
using umbraco.DataLayer;
using umbraco.BasePages;
using Umbraco.Core.IO;
@@ -52,7 +53,9 @@ namespace umbraco
? new ContentType(-1)
: new ContentType(ApplicationContext.Current.Services.ContentTypeService.GetContentType(parentId));
contentType.CreatorId = _userID;
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 = UmbracoSettings.IconPickerBehaviour == IconPickerBehaviour.HideFileDuplicates
? ".sprTreeFolder"