mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 19:54:57 +08:00
Fixing that the technical names of widgets couldn't contain hyphens, see #4981
This commit is contained in:
@@ -53,7 +53,7 @@ namespace Orchard.Widgets.Drivers {
|
||||
|
||||
// if there is a name, ensure it's unique
|
||||
if(!string.IsNullOrWhiteSpace(widgetPart.Name)) {
|
||||
widgetPart.Name = widgetPart.Name.ToSafeName();
|
||||
widgetPart.Name = widgetPart.Name.ToHtmlName();
|
||||
|
||||
var widgets = _contentManager.Query<WidgetPart, WidgetPartRecord>().Where(x => x.Name == widgetPart.Name && x.Id != widgetPart.Id).Count();
|
||||
if(widgets > 0) {
|
||||
|
@@ -191,6 +191,34 @@ namespace Orchard.Utility.Extensions {
|
||||
return name;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Generates a valid Html name.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Uses a white list set of chars.
|
||||
/// </remarks>
|
||||
public static string ToHtmlName(this string name) {
|
||||
if (String.IsNullOrWhiteSpace(name))
|
||||
return String.Empty;
|
||||
|
||||
name = RemoveDiacritics(name);
|
||||
name = name.Strip(c =>
|
||||
c != '-'
|
||||
&& c != '_'
|
||||
&& !c.IsLetter()
|
||||
&& !Char.IsDigit(c)
|
||||
);
|
||||
|
||||
name = name.Trim();
|
||||
|
||||
// don't allow non A-Z chars as first letter, as they are not allowed in prefixes
|
||||
while (name.Length > 0 && !IsLetter(name[0])) {
|
||||
name = name.Substring(1);
|
||||
}
|
||||
|
||||
return name;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Whether the char is a letter between A and Z or not
|
||||
/// </summary>
|
||||
|
Reference in New Issue
Block a user