diff --git a/src/Orchard.Tests/Environment/RunningShellTableTests.cs b/src/Orchard.Tests/Environment/RunningShellTableTests.cs index 0d5097128..88fe962a5 100644 --- a/src/Orchard.Tests/Environment/RunningShellTableTests.cs +++ b/src/Orchard.Tests/Environment/RunningShellTableTests.cs @@ -128,9 +128,10 @@ namespace Orchard.Tests.Environment { var settingsG = new ShellSettings { Name = "Gamma", RequestUrlHost = "wiki.example.com" }; var settingsD = new ShellSettings { Name = "Delta", RequestUrlPrefix = "Quux" }; table.Add(settings); + // add this shell first, because the order the shells where processed used to matter + table.Add(settingsG); table.Add(settingsA); table.Add(settingsB); - table.Add(settingsG); table.Add(settingsD); Assert.That(table.Match(new StubHttpContext("~/foo/bar", "wiki.example.com")), Is.EqualTo(settingsA).Using(new ShellComparer())); diff --git a/src/Orchard.Tests/Orchard.Framework.Tests.csproj b/src/Orchard.Tests/Orchard.Framework.Tests.csproj index 89155c400..a3ccd07a6 100644 --- a/src/Orchard.Tests/Orchard.Framework.Tests.csproj +++ b/src/Orchard.Tests/Orchard.Framework.Tests.csproj @@ -1,5 +1,6 @@  + Debug AnyCPU diff --git a/src/Orchard.Tests/packages.config b/src/Orchard.Tests/packages.config index c43cb3d10..786c65803 100644 --- a/src/Orchard.Tests/packages.config +++ b/src/Orchard.Tests/packages.config @@ -17,4 +17,5 @@ + \ No newline at end of file diff --git a/src/Orchard/Environment/RunningShellTable.cs b/src/Orchard/Environment/RunningShellTable.cs index b5322f7c4..b4c2f1ee7 100644 --- a/src/Orchard/Environment/RunningShellTable.cs +++ b/src/Orchard/Environment/RunningShellTable.cs @@ -84,7 +84,12 @@ namespace Orchard.Environment { .Select(h => new ShellSettings(s) {RequestUrlHost = h})) .GroupBy(s => s.RequestUrlHost ?? string.Empty) .OrderByDescending(g => g.Key.Length) - .ToDictionary(x => x.Key, x => x.AsEnumerable(), StringComparer.OrdinalIgnoreCase); + .ToDictionary( + x => x.Key, + // we want to keep this ordered so that, for the same host, shells with a configured + // RequestUrlPrefix are tested first when trying to match them to coming requests. + x => x.OrderByDescending(ss => (ss.RequestUrlPrefix ?? "").Length).AsEnumerable(), + StringComparer.OrdinalIgnoreCase); if (unqualified.Count() == 1) { // only one shell had no request url criteria @@ -164,20 +169,20 @@ namespace Orchard.Environment { shells = _shellsByHost[subHostKey]; } } - + // looking for a request url prefix match var mostQualifiedMatch = shells.FirstOrDefault(settings => { - if (settings.State == TenantState.Disabled) { - return false; - } + if (settings.State == TenantState.Disabled) { + return false; + } - if (String.IsNullOrWhiteSpace(settings.RequestUrlPrefix)) { - return true; - } - - return key.Equals(host + "/" + settings.RequestUrlPrefix, StringComparison.OrdinalIgnoreCase); - }); + if (String.IsNullOrWhiteSpace(settings.RequestUrlPrefix)) { + return true; + } + return key.Equals(host + "/" + settings.RequestUrlPrefix, StringComparison.OrdinalIgnoreCase); + }); + return mostQualifiedMatch ?? _fallback; });