Merge branch '6.2.0' of github.com:umbraco/Umbraco-CMS into 6.2.0

This commit is contained in:
Sebastiaan Janssen
2013-09-08 19:42:51 +02:00
3 changed files with 72 additions and 3 deletions

View File

@@ -28,6 +28,17 @@ namespace Umbraco.Core
[UmbracoWillObsolete("Do not use this constants. See IShortStringHelper.CleanStringForSafeAliasJavaScriptCode.")]
public const string UmbracoInvalidFirstCharacters = "01234567890";
private static readonly char[] ToCSharpHexDigitLower = "0123456789abcdef".ToCharArray();
private static readonly char[] ToCSharpEscapeChars;
static StringExtensions()
{
var escapes = new[] { "\aa", "\bb", "\ff", "\nn", "\rr", "\tt", "\vv", "\"\"", "\\\\", "??", "\00" };
ToCSharpEscapeChars = new char[escapes.Max(e => e[0]) + 1];
foreach (var escape in escapes)
ToCSharpEscapeChars[escape[0]] = escape[1];
}
internal static string ReplaceNonAlphanumericChars(this string input, char replacement)
{
//any character that is not alphanumeric, convert to a hyphen
@@ -1085,5 +1096,46 @@ namespace Umbraco.Core
return source;
}
/// <summary>
/// Converts a literal string into a C# expression.
/// </summary>
/// <param name="s">Current instance of the string.</param>
/// <returns>The string in a C# format.</returns>
public static string ToCSharpString(this string s)
{
if (s == null) return "<null>";
// http://stackoverflow.com/questions/323640/can-i-convert-a-c-sharp-string-value-to-an-escaped-string-literal
var sb = new StringBuilder(s.Length + 2);
for (var rp = 0; rp < s.Length; rp++)
{
var c = s[rp];
if (c < ToCSharpEscapeChars.Length && '\0' != ToCSharpEscapeChars[c])
sb.Append('\\').Append(ToCSharpEscapeChars[c]);
else if ('~' >= c && c >= ' ')
sb.Append(c);
else
sb.Append(@"\x")
.Append(ToCSharpHexDigitLower[c >> 12 & 0x0F])
.Append(ToCSharpHexDigitLower[c >> 8 & 0x0F])
.Append(ToCSharpHexDigitLower[c >> 4 & 0x0F])
.Append(ToCSharpHexDigitLower[c & 0x0F]);
}
return sb.ToString();
// requires full trust
/*
using (var writer = new StringWriter())
using (var provider = CodeDomProvider.CreateProvider("CSharp"))
{
provider.GenerateCodeFromExpression(new CodePrimitiveExpression(s), writer, null);
return writer.ToString().Replace(string.Format("\" +{0}\t\"", Environment.NewLine), "");
}
*/
}
}
}

View File

@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.Configuration;
using System.IO;
using System.Linq;
@@ -116,12 +117,18 @@ namespace Umbraco.Tests.TestHelpers
}
public static void CleanDirectories(string[] directories)
{
{
var preserves = new Dictionary<string, string[]>
{
{ SystemDirectories.Masterpages, new[] {"dummy.txt"} },
{ SystemDirectories.MvcViews, new[] {"dummy.txt"} }
};
foreach (var directory in directories)
{
var directoryInfo = new DirectoryInfo(IOHelper.MapPath(directory));
var preserve = preserves.ContainsKey(directory) ? preserves[directory] : null;
if (directoryInfo.Exists)
directoryInfo.GetFiles().ForEach(x => x.Delete());
directoryInfo.GetFiles().Where(x => preserve == null || preserve.Contains(x.Name) == false).ForEach(x => x.Delete());
}
}

View File

@@ -1,4 +1,5 @@
using System;
using Umbraco.Core;
using umbraco.cms.businesslogic.web;
namespace Umbraco.Web.Routing
@@ -20,7 +21,16 @@ namespace Umbraco.Web.Routing
public DomainAndUri(Domain domain, string scheme)
{
Domain = domain;
Uri = new Uri(UriUtility.TrimPathEndSlash(UriUtility.StartWithScheme(domain.Name, scheme)));
try
{
Uri = new Uri(UriUtility.TrimPathEndSlash(UriUtility.StartWithScheme(domain.Name, scheme)));
}
catch (UriFormatException)
{
var name = domain.Name.ToCSharpString();
throw new ArgumentException(string.Format("Failed to parse invalid domain: node id={0}, hostname=\"{1}\"."
+ " Hostname should be a valid uri.", domain.RootNodeId, name), "domain");
}
}
/// <summary>