mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2026-02-09 09:16:41 +08:00
#17842: Exception when content type name contains special chars
Work Items: 17842 --HG-- branch : 1.x
This commit is contained in:
@@ -58,6 +58,10 @@ namespace Orchard.ContentTypes.Controllers {
|
||||
ModelState.AddModelError("Name", T("A type with the same Id already exists.").ToString());
|
||||
}
|
||||
|
||||
if (!String.IsNullOrWhiteSpace(viewModel.Name) && !ContentDefinitionService.IsLetter(viewModel.Name[0])) {
|
||||
ModelState.AddModelError("Name", T("The technical name must start with a letter.").ToString());
|
||||
}
|
||||
|
||||
if (_contentDefinitionService.GetTypes().Any(t => String.Equals(t.DisplayName.Trim(), viewModel.DisplayName.Trim(), StringComparison.OrdinalIgnoreCase))) {
|
||||
ModelState.AddModelError("DisplayName", T("A type with the same Name already exists.").ToString());
|
||||
}
|
||||
|
||||
@@ -71,6 +71,11 @@ namespace Orchard.ContentTypes.Services {
|
||||
if(String.IsNullOrWhiteSpace(name)) {
|
||||
name = GenerateContentTypeNameFromDisplayName(displayName);
|
||||
}
|
||||
else {
|
||||
if(!IsLetter(name[0])) {
|
||||
throw new ArgumentException("Content type name must start with a letter", "name");
|
||||
}
|
||||
}
|
||||
|
||||
while ( _contentDefinitionManager.GetTypeDefinition(name) != null )
|
||||
name = VersionName(name);
|
||||
@@ -235,11 +240,23 @@ namespace Orchard.ContentTypes.Services {
|
||||
name = dissallowed.Replace(name, String.Empty);
|
||||
name = name.Trim();
|
||||
|
||||
// don't allow non A-Z chars as first letter, as they are not allowed in prefixes
|
||||
if(name.Length > 0) {
|
||||
if (!IsLetter(name[0])) {
|
||||
name = name.Substring(1);
|
||||
}
|
||||
}
|
||||
|
||||
if (name.Length > 128)
|
||||
name = name.Substring(0, 128);
|
||||
|
||||
return name;
|
||||
}
|
||||
|
||||
public static bool IsLetter(char c) {
|
||||
return ('A' <= c && c <= 'Z') || ('a' <= c && c <= 'z');
|
||||
}
|
||||
|
||||
//gratuitously stolen from the RoutableService
|
||||
public string GenerateContentTypeNameFromDisplayName(string displayName) {
|
||||
displayName = SafeName(displayName);
|
||||
|
||||
Reference in New Issue
Block a user