mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 19:54:57 +08:00
Fixing ShellTable mismatch when using a slug starting with another's Url Prefix
--HG-- branch : 1.x extra : rebase_source : 2f2761fc4db442c5ad64001d6dc8836193bd0528
This commit is contained in:
@@ -135,6 +135,7 @@ namespace Orchard.Tests.Environment {
|
|||||||
|
|
||||||
Assert.That(table.Match(new StubHttpContext("~/foo/bar", "wiki.example.com")), Is.EqualTo(settingsA).Using(new ShellComparer()));
|
Assert.That(table.Match(new StubHttpContext("~/foo/bar", "wiki.example.com")), Is.EqualTo(settingsA).Using(new ShellComparer()));
|
||||||
Assert.That(table.Match(new StubHttpContext("~/bar/foo", "wiki.example.com")), Is.EqualTo(settingsB).Using(new ShellComparer()));
|
Assert.That(table.Match(new StubHttpContext("~/bar/foo", "wiki.example.com")), Is.EqualTo(settingsB).Using(new ShellComparer()));
|
||||||
|
Assert.That(table.Match(new StubHttpContext("~/", "wiki.example.com")), Is.EqualTo(settingsG).Using(new ShellComparer()));
|
||||||
Assert.That(table.Match(new StubHttpContext("~/baaz", "wiki.example.com")), Is.EqualTo(settingsG).Using(new ShellComparer()));
|
Assert.That(table.Match(new StubHttpContext("~/baaz", "wiki.example.com")), Is.EqualTo(settingsG).Using(new ShellComparer()));
|
||||||
Assert.That(table.Match(new StubHttpContext("~/foo/bar", "www.example.com")), Is.EqualTo(settings).Using(new ShellComparer()));
|
Assert.That(table.Match(new StubHttpContext("~/foo/bar", "www.example.com")), Is.EqualTo(settings).Using(new ShellComparer()));
|
||||||
Assert.That(table.Match(new StubHttpContext("~/bar/foo", "www.example.com")), Is.EqualTo(settings).Using(new ShellComparer()));
|
Assert.That(table.Match(new StubHttpContext("~/bar/foo", "www.example.com")), Is.EqualTo(settings).Using(new ShellComparer()));
|
||||||
@@ -149,6 +150,21 @@ namespace Orchard.Tests.Environment {
|
|||||||
Assert.That(table.Match(new StubHttpContext("~/yarg", "a.example.com")), Is.Null);
|
Assert.That(table.Match(new StubHttpContext("~/yarg", "a.example.com")), Is.Null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void PathAndHostMustMatchOnFullUrl() {
|
||||||
|
var table = (IRunningShellTable)new RunningShellTable();
|
||||||
|
var settings = new ShellSettings { Name = ShellSettings.DefaultName, RequestUrlHost = "www.example.com", };
|
||||||
|
var settingsB = new ShellSettings { Name = "Beta", RequestUrlHost = "wiki.example.com", RequestUrlPrefix = "bar" };
|
||||||
|
var settingsG = new ShellSettings { Name = "Gamma", RequestUrlHost = "wiki.example.com" };
|
||||||
|
table.Add(settings);
|
||||||
|
table.Add(settingsB);
|
||||||
|
table.Add(settingsG);
|
||||||
|
|
||||||
|
Assert.That(table.Match(new StubHttpContext("~/bar/foo", "wiki.example.com")), Is.EqualTo(settingsB).Using(new ShellComparer()));
|
||||||
|
Assert.That(table.Match(new StubHttpContext("~/", "wiki.example.com")), Is.EqualTo(settingsG).Using(new ShellComparer()));
|
||||||
|
Assert.That(table.Match(new StubHttpContext("~/baaz", "wiki.example.com")), Is.EqualTo(settingsG).Using(new ShellComparer()));
|
||||||
|
Assert.That(table.Match(new StubHttpContext("~/barbaz", "wiki.example.com")), Is.EqualTo(settingsG).Using(new ShellComparer()));
|
||||||
|
}
|
||||||
[Test]
|
[Test]
|
||||||
public void PathAloneWillMatch() {
|
public void PathAloneWillMatch() {
|
||||||
var table = (IRunningShellTable)new RunningShellTable();
|
var table = (IRunningShellTable)new RunningShellTable();
|
||||||
|
@@ -93,7 +93,18 @@ namespace Orchard.Environment {
|
|||||||
.Where(group => host.EndsWith(group.Key, StringComparison.OrdinalIgnoreCase))
|
.Where(group => host.EndsWith(group.Key, StringComparison.OrdinalIgnoreCase))
|
||||||
.SelectMany(group => group
|
.SelectMany(group => group
|
||||||
.OrderByDescending(settings => (settings.RequestUrlPrefix ?? string.Empty).Length))
|
.OrderByDescending(settings => (settings.RequestUrlPrefix ?? string.Empty).Length))
|
||||||
.FirstOrDefault(settings => settings.State.CurrentState != TenantState.State.Disabled && appRelativePath.StartsWith("~/" + (settings.RequestUrlPrefix ?? string.Empty), StringComparison.OrdinalIgnoreCase));
|
.FirstOrDefault(settings => {
|
||||||
|
if (settings.State.CurrentState == TenantState.State.Disabled) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (String.IsNullOrWhiteSpace(settings.RequestUrlPrefix)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return appRelativePath.StartsWith("~/" + settings.RequestUrlPrefix + "/", StringComparison.OrdinalIgnoreCase)
|
||||||
|
|| appRelativePath.Equals("~/" + settings.RequestUrlPrefix, StringComparison.OrdinalIgnoreCase);
|
||||||
|
});
|
||||||
|
|
||||||
return mostQualifiedMatch ?? _fallback;
|
return mostQualifiedMatch ?? _fallback;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user