Fixes issues related to UrlResolving. Work items: 30353, 30324 and 30352
This commit is contained in:
@@ -68,6 +68,11 @@
|
||||
<!-- Cache cycle of Media and Member data fetched from the umbraco.library methods -->
|
||||
<!-- In seconds. 0 will disable cache -->
|
||||
<UmbracoLibraryCacheDuration>1800</UmbracoLibraryCacheDuration>
|
||||
|
||||
<!-- Url Resolving ensures that all links works if you run Umbraco in virtual directories -->
|
||||
<!-- Setting this to false can increase render time for pages with a large number of links -->
|
||||
<!-- If running Umbraco in virtual directory this *must* be set to true! -->
|
||||
<ResolveUrlsFromTextString>true</ResolveUrlsFromTextString>
|
||||
</content>
|
||||
|
||||
<requestHandler>
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.IO;
|
||||
@@ -14,6 +15,8 @@ namespace umbraco.IO
|
||||
public static class IOHelper
|
||||
{
|
||||
private static string m_rootDir = "";
|
||||
// static compiled regex for faster performance
|
||||
private readonly static Regex _resolveUrlPattern = new Regex("(=[\"\']?)(\\W?\\~(?:.(?![\"\']?\\s+(?:\\S+)=|[>\"\']))+.)[\"\']?", RegexOptions.Compiled | RegexOptions.IgnoreCase | RegexOptions.IgnorePatternWhitespace);
|
||||
|
||||
public static char DirSepChar
|
||||
{
|
||||
@@ -46,31 +49,47 @@ namespace umbraco.IO
|
||||
return VirtualPathUtility.ToAbsolute(virtualPath, SystemDirectories.Root);
|
||||
}
|
||||
|
||||
|
||||
public static string ResolveUrlsFromTextString(string text)
|
||||
{
|
||||
// find all relative urls (ie. urls that contain ~)
|
||||
// string pattern = "(\\S+)=[\"']?(\\W?\\~(?:.(?![\"']?\\s+(?:\\S+)=|[>\"']))+.)[\"']?";
|
||||
string pattern = "<.*?\\\"(\\~.*?)\\\"";
|
||||
MatchCollection tags =
|
||||
Regex.Matches(text, pattern, RegexOptions.IgnoreCase | RegexOptions.IgnorePatternWhitespace);
|
||||
foreach (Match tag in tags)
|
||||
if (UmbracoSettings.ResolveUrlsFromTextString)
|
||||
{
|
||||
string url = "";
|
||||
if (tag.Groups[1].Success)
|
||||
url = tag.Groups[1].Value;
|
||||
Stopwatch sw = new Stopwatch();
|
||||
sw.Start();
|
||||
Debug.WriteLine("Start: " + sw.ElapsedMilliseconds);
|
||||
|
||||
// The richtext editor inserts a slash in front of the url. That's why we need this little fix
|
||||
// if (url.StartsWith("/"))
|
||||
// text = text.Replace(url, ResolveUrl(url.Substring(1)));
|
||||
// else
|
||||
if (!String.IsNullOrEmpty(url))
|
||||
// find all relative urls (ie. urls that contain ~)
|
||||
MatchCollection tags =
|
||||
_resolveUrlPattern.Matches(text);
|
||||
Debug.WriteLine("After regex: " + sw.ElapsedMilliseconds);
|
||||
foreach (Match tag in tags)
|
||||
{
|
||||
string resolvedUrl = (url.Substring(0,1) == "/") ? ResolveUrl(url.Substring(1)) : ResolveUrl(url);
|
||||
text = text.Replace(url, resolvedUrl);
|
||||
Debug.WriteLine("-- inside regex: " + sw.ElapsedMilliseconds);
|
||||
string url = "";
|
||||
if (tag.Groups[1].Success)
|
||||
url = tag.Groups[1].Value;
|
||||
|
||||
// The richtext editor inserts a slash in front of the url. That's why we need this little fix
|
||||
// if (url.StartsWith("/"))
|
||||
// text = text.Replace(url, ResolveUrl(url.Substring(1)));
|
||||
// else
|
||||
if (!String.IsNullOrEmpty(url))
|
||||
{
|
||||
Debug.WriteLine("---- before resolve: " + sw.ElapsedMilliseconds);
|
||||
string resolvedUrl = (url.Substring(0, 1) == "/") ? ResolveUrl(url.Substring(1)) : ResolveUrl(url);
|
||||
Debug.WriteLine("---- after resolve: " + sw.ElapsedMilliseconds);
|
||||
Debug.WriteLine("---- before replace: " + sw.ElapsedMilliseconds);
|
||||
text = text.Replace(url, resolvedUrl);
|
||||
Debug.WriteLine("---- after replace: " + sw.ElapsedMilliseconds);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Debug.WriteLine("total: " + sw.ElapsedMilliseconds);
|
||||
sw.Stop();
|
||||
System.Web.HttpContext.Current.Trace.Write("Resolve Urls", sw.ElapsedMilliseconds.ToString());
|
||||
|
||||
}
|
||||
return text;
|
||||
}
|
||||
|
||||
@@ -154,7 +173,7 @@ namespace umbraco.IO
|
||||
throw new FileSecurityException(String.Format("The extension for the current file '{0}' is not of an allowed type for this editor. This is typically controlled from either the installed MacroEngines or based on configuration in /config/umbracoSettings.config", filePath.Replace(MapPath(SystemDirectories.Root), "")));
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Web;
|
||||
using System.Web.Caching;
|
||||
@@ -13,7 +14,6 @@ namespace umbraco
|
||||
/// </summary>
|
||||
public class UmbracoSettings
|
||||
{
|
||||
// TODO: Remove for launch
|
||||
public const string TEMP_FRIENDLY_XML_CHILD_CONTAINER_NODENAME = ""; // "children";
|
||||
|
||||
/// <summary>
|
||||
@@ -928,6 +928,34 @@ namespace umbraco
|
||||
}
|
||||
}
|
||||
|
||||
private static bool? _resolveUrlsFromTextString;
|
||||
public static bool ResolveUrlsFromTextString
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_resolveUrlsFromTextString == null)
|
||||
{
|
||||
try
|
||||
{
|
||||
bool enableDictionaryFallBack;
|
||||
var value = GetKey("/settings/content/ResolveUrlsFromTextString");
|
||||
if (value != null)
|
||||
if (bool.TryParse(value, out enableDictionaryFallBack))
|
||||
_resolveUrlsFromTextString = enableDictionaryFallBack;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Trace.WriteLine("Could not load /settings/content/ResolveUrlsFromTextString from umbracosettings.config:\r\n {0}",
|
||||
ex.Message);
|
||||
|
||||
// set url resolving to true (default (legacy) behavior) to ensure we don't keep writing to trace
|
||||
_resolveUrlsFromTextString = true;
|
||||
}
|
||||
}
|
||||
return _resolveUrlsFromTextString == true;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Configuration regarding webservices
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user