TestCase added and IUrlHelper and support for RouteOptions.LowercaseUrls
checked appliesd to the query string. @rynowak #518 #Issue: aspnet/Mvc#7720
This commit is contained in:
parent
f227cbeca3
commit
cb77c17cf4
|
|
@ -139,7 +139,7 @@ namespace Microsoft.AspNetCore.Routing
|
||||||
|
|
||||||
var url = pathData.VirtualPath;
|
var url = pathData.VirtualPath;
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(url) && (_options.LowercaseUrls || _options.LowercaseQueryStrings || _options.AppendTrailingSlash))
|
if (!string.IsNullOrEmpty(url) && (_options.LowercaseUrls || _options.AppendTrailingSlash))
|
||||||
{
|
{
|
||||||
var indexOfSeparator = url.IndexOfAny(UrlQueryDelimiters);
|
var indexOfSeparator = url.IndexOfAny(UrlQueryDelimiters);
|
||||||
var urlWithoutQueryString = url;
|
var urlWithoutQueryString = url;
|
||||||
|
|
@ -156,7 +156,7 @@ namespace Microsoft.AspNetCore.Routing
|
||||||
urlWithoutQueryString = urlWithoutQueryString.ToLowerInvariant();
|
urlWithoutQueryString = urlWithoutQueryString.ToLowerInvariant();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_options.LowercaseQueryStrings)
|
if (_options.LowercaseUrls && _options.LowercaseQueryStrings)
|
||||||
{
|
{
|
||||||
queryString = queryString.ToLowerInvariant();
|
queryString = queryString.ToLowerInvariant();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ namespace Microsoft.AspNetCore.Routing
|
||||||
public bool LowercaseUrls { get; set; }
|
public bool LowercaseUrls { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets a value indicating whether all generated QUERY STRINGS are lower-case.
|
/// Gets or sets a value indicating whether all generated QUERY STRINGS are lower-case. property will when LowercaseUrls true.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public bool LowercaseQueryStrings { get; set; }
|
public bool LowercaseQueryStrings { get; set; }
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -89,6 +89,44 @@ namespace Microsoft.AspNetCore.Routing
|
||||||
Assert.Empty(pathData.DataTokens);
|
Assert.Empty(pathData.DataTokens);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Theory]
|
||||||
|
[InlineData(@"Home/Index/23?Param1=ABC&Param2=Xyz", "/Home/Index/23?Param1=ABC&Param2=Xyz", false, true, false)]
|
||||||
|
[InlineData(@"Home/Index/23?Param1=ABC&Param2=Xyz", "/Home/Index/23?Param1=ABC&Param2=Xyz", false, false, false)]
|
||||||
|
[InlineData(@"Home/Index/23?Param1=ABC&Param2=Xyz", "/home/index/23/?param1=abc¶m2=xyz", true, true, true)]
|
||||||
|
[InlineData(@"Home/Index/23#Param1=ABC&Param2=Xyz", "/Home/Index/23/#Param1=ABC&Param2=Xyz", false, true, true)]
|
||||||
|
[InlineData(@"Home/Index/23#Param1=ABC&Param2=Xyz", "/home/index/23#Param1=ABC&Param2=Xyz", true, false, false)]
|
||||||
|
[InlineData(@"Home/Index/23/?Param1=ABC&Param2=Xyz", "/home/index/23/?param1=abc¶m2=xyz", true, true, true)]
|
||||||
|
[InlineData(@"Home/Index/23/#Param1=ABC&Param2=Xyz", "/home/index/23/#Param1=ABC&Param2=Xyz", true, false, true)]
|
||||||
|
[InlineData(@"Home/Index/23/#Param1=ABC&Param2=Xyz", "/home/index/23/#param1=abc¶m2=xyz", true, true, true)]
|
||||||
|
public void GetVirtualPath_CanLowerCaseUrls_QueryStrings_BasedOnOptions(
|
||||||
|
string returnUrl,
|
||||||
|
string expectedUrl,
|
||||||
|
bool lowercaseUrls,
|
||||||
|
bool lowercaseQueryStrings, bool appendTrailingSlash)
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var target = new Mock<IRouter>(MockBehavior.Strict);
|
||||||
|
target
|
||||||
|
.Setup(e => e.GetVirtualPath(It.IsAny<VirtualPathContext>()))
|
||||||
|
.Returns(new VirtualPathData(target.Object, returnUrl));
|
||||||
|
|
||||||
|
var routeCollection = new RouteCollection();
|
||||||
|
routeCollection.Add(target.Object);
|
||||||
|
var virtualPathContext = CreateVirtualPathContext(
|
||||||
|
options: GetRouteOptions(
|
||||||
|
lowerCaseUrls: lowercaseUrls,
|
||||||
|
lowercaseQueryStrings: lowercaseQueryStrings,
|
||||||
|
appendTrailingSlash: appendTrailingSlash));
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var pathData = routeCollection.GetVirtualPath(virtualPathContext);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Assert.Equal(expectedUrl, pathData.VirtualPath);
|
||||||
|
Assert.Same(target.Object, pathData.Router);
|
||||||
|
Assert.Empty(pathData.DataTokens);
|
||||||
|
}
|
||||||
|
|
||||||
[Theory]
|
[Theory]
|
||||||
[MemberData(nameof(DataTokensTestData))]
|
[MemberData(nameof(DataTokensTestData))]
|
||||||
public void GetVirtualPath_ReturnsDataTokens(RouteValueDictionary dataTokens, string routerName)
|
public void GetVirtualPath_ReturnsDataTokens(RouteValueDictionary dataTokens, string routerName)
|
||||||
|
|
@ -663,12 +701,13 @@ namespace Microsoft.AspNetCore.Routing
|
||||||
|
|
||||||
private static Action<RouteOptions> GetRouteOptions(
|
private static Action<RouteOptions> GetRouteOptions(
|
||||||
bool lowerCaseUrls = false,
|
bool lowerCaseUrls = false,
|
||||||
bool appendTrailingSlash = false)
|
bool appendTrailingSlash = false, bool lowercaseQueryStrings = false)
|
||||||
{
|
{
|
||||||
return (options) =>
|
return (options) =>
|
||||||
{
|
{
|
||||||
options.LowercaseUrls = lowerCaseUrls;
|
options.LowercaseUrls = lowerCaseUrls;
|
||||||
options.AppendTrailingSlash = appendTrailingSlash;
|
options.AppendTrailingSlash = appendTrailingSlash;
|
||||||
|
options.LowercaseQueryStrings = lowercaseQueryStrings;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue