From d1b05332c58d5b6081981d43da3c2a25547ed2f8 Mon Sep 17 00:00:00 2001 From: Morten Christensen Date: Thu, 7 Mar 2013 20:28:13 -0100 Subject: [PATCH] Manually adds fix for U4-1869 from 6.0.3 branch --- src/Umbraco.Core/IO/IOHelper.cs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/Umbraco.Core/IO/IOHelper.cs b/src/Umbraco.Core/IO/IOHelper.cs index a53ae8d924..aaf5298447 100644 --- a/src/Umbraco.Core/IO/IOHelper.cs +++ b/src/Umbraco.Core/IO/IOHelper.cs @@ -8,6 +8,7 @@ using System.IO; using System.Configuration; using System.Web; using System.Text.RegularExpressions; +using System.Xml; using Umbraco.Core.Configuration; using Umbraco.Core.Logging; @@ -228,6 +229,20 @@ namespace Umbraco.Core.IO filePath = String.Empty; } + //Break up the file in name and extension before applying the UrlReplaceCharacters + var fileNamePart = filePath.Substring(0, filePath.LastIndexOf('.')); + var ext = filePath.Substring(filePath.LastIndexOf('.')); + + //Because the file usually is downloadable as well we check characters against 'UmbracoSettings.UrlReplaceCharacters' + XmlNode replaceChars = UmbracoSettings.UrlReplaceCharacters; + foreach (XmlNode n in replaceChars.SelectNodes("char")) + { + if (n.Attributes.GetNamedItem("org") != null && n.Attributes.GetNamedItem("org").Value != "") + fileNamePart = fileNamePart.Replace(n.Attributes.GetNamedItem("org").Value, XmlHelper.GetNodeValue(n)); + } + + filePath = string.Concat(fileNamePart, ext); + // Adapted from: http://stackoverflow.com/a/4827510/5018 // Combined both Reserved Characters and Character Data // from http://en.wikipedia.org/wiki/Percent-encoding