diff --git a/src/Orchard/Environment/Extensions/ExtensionLoaderCoordinator.cs b/src/Orchard/Environment/Extensions/ExtensionLoaderCoordinator.cs index 964dbb6a5..8cc499a13 100644 --- a/src/Orchard/Environment/Extensions/ExtensionLoaderCoordinator.cs +++ b/src/Orchard/Environment/Extensions/ExtensionLoaderCoordinator.cs @@ -87,14 +87,14 @@ namespace Orchard.Environment.Extensions { private string GetExtensionHash(ExtensionLoadingContext context, DependencyDescriptor dependencyDescriptor) { var hash = new Hash(); - hash.AddString(dependencyDescriptor.Name); + hash.AddStringInvariant(dependencyDescriptor.Name); foreach (var virtualpathDependency in context.ProcessedExtensions[dependencyDescriptor.Name].VirtualPathDependencies) { hash.AddDateTime(GetVirtualPathModificationTimeUtc(context.VirtualPathModficationDates, virtualpathDependency)); } foreach (var reference in dependencyDescriptor.References) { - hash.AddString(reference.Name); + hash.AddStringInvariant(reference.Name); hash.AddString(reference.LoaderName); hash.AddDateTime(GetVirtualPathModificationTimeUtc(context.VirtualPathModficationDates, reference.VirtualPath)); } diff --git a/src/Orchard/Utility/Hash.cs b/src/Orchard/Utility/Hash.cs index dacfead52..7cfa01c10 100644 --- a/src/Orchard/Utility/Hash.cs +++ b/src/Orchard/Utility/Hash.cs @@ -10,12 +10,28 @@ namespace Orchard.Utility { public class Hash { private long _hash; - public string Value { get { return _hash.ToString("x", CultureInfo.InvariantCulture); } } + public string Value { + get { + return _hash.ToString("x", CultureInfo.InvariantCulture); + } + } + + public override string ToString() { + return Value; + } public void AddString(string value) { if (string.IsNullOrEmpty(value)) return; - _hash += value.GetHashCode(); + + _hash += GetStringHashCode(value); + } + + public void AddStringInvariant(string value) { + if (string.IsNullOrEmpty(value)) + return; + + AddString(value.ToLowerInvariant()); } public void AddTypeReference(Type type) { @@ -24,7 +40,22 @@ namespace Orchard.Utility { } public void AddDateTime(DateTime dateTime) { - _hash += dateTime.ToUniversalTime().ToBinary(); + _hash += dateTime.ToBinary(); + } + + /// + /// We need a custom string hash code function, because .NET string.GetHashCode() + /// function is not guaranteed to be constant across multiple executions. + /// + private static long GetStringHashCode(string s) { + unchecked { + long result = 352654597L; + foreach (var ch in s) { + long h = ch.GetHashCode(); + result = result + (h << 27) + h; + } + return result; + } } } }