From 035f3d3e9c03f9930d1fcaaa4c2e4d3b339e73c3 Mon Sep 17 00:00:00 2001 From: Andre Rodrigues Date: Thu, 9 Dec 2010 18:03:27 -0800 Subject: [PATCH] #16803: International characters are allowed to go through and accents are removed. --HG-- branch : dev --- .../Core/Routable/Services/RoutableService.cs | 23 +++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/src/Orchard.Web/Core/Routable/Services/RoutableService.cs b/src/Orchard.Web/Core/Routable/Services/RoutableService.cs index 2ddea2f21..68dc30218 100644 --- a/src/Orchard.Web/Core/Routable/Services/RoutableService.cs +++ b/src/Orchard.Web/Core/Routable/Services/RoutableService.cs @@ -1,6 +1,8 @@ using System; using System.Collections.Generic; +using System.Globalization; using System.Linq; +using System.Text; using System.Text.RegularExpressions; using Orchard.ContentManagement; 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 model) where TModel : IRoutableAspect { if (!string.IsNullOrEmpty(model.Slug) || string.IsNullOrEmpty(model.Title)) return; 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('-'); 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 slug = slug.Trim('.'); - - model.Slug = slug.ToLowerInvariant(); + model.Slug = RemoveDiacritics(slug.ToLower()); } public string GenerateUniqueSlug(IRoutableAspect part, IEnumerable existingPaths) {