mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-07-15 19:49:51 +08:00
#16803: International characters are allowed to go through and accents are removed.
--HG-- branch : dev
This commit is contained in:
parent
4a9fb5a857
commit
035f3d3e9c
@ -1,6 +1,8 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Globalization;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
using Orchard.ContentManagement;
|
using Orchard.ContentManagement;
|
||||||
using Orchard.ContentManagement.Aspects;
|
using Orchard.ContentManagement.Aspects;
|
||||||
@ -27,14 +29,28 @@ namespace Orchard.Core.Routable.Services {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static string RemoveDiacritics(string slug) {
|
||||||
|
string stFormD = slug.Normalize(NormalizationForm.FormD);
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
|
||||||
|
for (int ich = 0; ich < stFormD.Length; ich++) {
|
||||||
|
UnicodeCategory uc = CharUnicodeInfo.GetUnicodeCategory(stFormD[ich]);
|
||||||
|
if (uc != UnicodeCategory.NonSpacingMark) {
|
||||||
|
sb.Append(stFormD[ich]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return (sb.ToString().Normalize(NormalizationForm.FormC));
|
||||||
|
}
|
||||||
|
|
||||||
public void FillSlugFromTitle<TModel>(TModel model) where TModel : IRoutableAspect {
|
public void FillSlugFromTitle<TModel>(TModel model) where TModel : IRoutableAspect {
|
||||||
if (!string.IsNullOrEmpty(model.Slug) || string.IsNullOrEmpty(model.Title))
|
if (!string.IsNullOrEmpty(model.Slug) || string.IsNullOrEmpty(model.Title))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var slug = model.Title;
|
var slug = model.Title;
|
||||||
var dissallowed = new Regex(@"[/:?#\[\]@!$&'()*+,;=\s\""\<\>]+");
|
var disallowed = new Regex(@"[/:?#\[\]@!$&'()*+,;=\s\""\<\>]+");
|
||||||
|
|
||||||
slug = dissallowed.Replace(slug, "-");
|
slug = disallowed.Replace(slug, "-");
|
||||||
slug = slug.Trim('-');
|
slug = slug.Trim('-');
|
||||||
|
|
||||||
if (slug.Length > 1000)
|
if (slug.Length > 1000)
|
||||||
@ -42,8 +58,7 @@ namespace Orchard.Core.Routable.Services {
|
|||||||
|
|
||||||
// dots are not allowed at the begin and the end of routes
|
// dots are not allowed at the begin and the end of routes
|
||||||
slug = slug.Trim('.');
|
slug = slug.Trim('.');
|
||||||
|
model.Slug = RemoveDiacritics(slug.ToLower());
|
||||||
model.Slug = slug.ToLowerInvariant();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public string GenerateUniqueSlug(IRoutableAspect part, IEnumerable<string> existingPaths) {
|
public string GenerateUniqueSlug(IRoutableAspect part, IEnumerable<string> existingPaths) {
|
||||||
|
Loading…
Reference in New Issue
Block a user