зеркало из https://github.com/aspnet/Routing.git
CR feedback
This commit is contained in:
Родитель
64c29fe813
Коммит
4f71137cbd
|
@ -42,6 +42,14 @@ namespace Microsoft.AspNet.Routing
|
|||
get { return GetString("TemplateRoute_CannotHaveOptionalParameterInMultiSegment"); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A catch-all parameter cannot be marked optional.
|
||||
/// </summary>
|
||||
internal static string TemplateRoute_CatchAllCannotBeOptional
|
||||
{
|
||||
get { return GetString("TemplateRoute_CatchAllCannotBeOptional"); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A catch-all parameter can only appear as the last segment of the route template.
|
||||
/// </summary>
|
||||
|
|
|
@ -129,6 +129,9 @@
|
|||
<data name="TemplateRoute_CannotHaveOptionalParameterInMultiSegment" xml:space="preserve">
|
||||
<value>A path segment that contains more than one section, such as a literal section or a parameter, cannot contain an optional parameter.</value>
|
||||
</data>
|
||||
<data name="TemplateRoute_CatchAllCannotBeOptional" xml:space="preserve">
|
||||
<value>A catch-all parameter cannot be marked optional.</value>
|
||||
</data>
|
||||
<data name="TemplateRoute_CatchAllMustBeLast" xml:space="preserve">
|
||||
<value>A catch-all parameter can only appear as the last segment of the route template.</value>
|
||||
</data>
|
||||
|
|
|
@ -178,6 +178,12 @@ namespace Microsoft.AspNet.Routing.Template
|
|||
var isCatchAll = rawName.StartsWith("*", StringComparison.Ordinal);
|
||||
var isOptional = rawName.EndsWith("?", StringComparison.Ordinal);
|
||||
|
||||
if (isCatchAll && isOptional)
|
||||
{
|
||||
context.Error = Resources.TemplateRoute_CatchAllCannotBeOptional;
|
||||
return false;
|
||||
}
|
||||
|
||||
rawName = isCatchAll ? rawName.Substring(1) : rawName;
|
||||
rawName = isOptional ? rawName.Substring(0, rawName.Length - 1) : rawName;
|
||||
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
using System;
|
||||
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Xunit;
|
||||
using Xunit.Extensions;
|
||||
|
||||
|
@ -384,6 +383,15 @@ namespace Microsoft.AspNet.Routing.Template.Tests
|
|||
"A path segment that contains more than one section, such as a literal section or a parameter, cannot contain an optional parameter." + Environment.NewLine +
|
||||
"Parameter name: routeTemplate");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void InvalidTemplate_CatchAllMarkedOptional()
|
||||
{
|
||||
Assert.Throws<ArgumentException>(
|
||||
() => TemplateParser.Parse("{a}/{*b?}"),
|
||||
"A catch-all parameter cannot be marked optional." + Environment.NewLine +
|
||||
"Parameter name: routeTemplate");
|
||||
}
|
||||
|
||||
private class TemplateParsedRouteEqualityComparer : IEqualityComparer<ParsedTemplate>
|
||||
{
|
||||
|
|
|
@ -722,6 +722,8 @@ namespace Microsoft.AspNet.Routing.Template.Tests
|
|||
|
||||
// Assert
|
||||
Assert.NotNull(match);
|
||||
Assert.Equal(2, match.Values.Count);
|
||||
Assert.Equal("Home", match.Values["controller"]);
|
||||
Assert.Equal("Index", match.Values["action"]);
|
||||
}
|
||||
|
||||
|
@ -737,6 +739,8 @@ namespace Microsoft.AspNet.Routing.Template.Tests
|
|||
|
||||
// Assert
|
||||
Assert.NotNull(match);
|
||||
Assert.Equal(1, match.Values.Count);
|
||||
Assert.Equal("Home", match.Values["controller"]);
|
||||
Assert.False(match.Values.ContainsKey("action"));
|
||||
}
|
||||
|
||||
|
@ -752,6 +756,8 @@ namespace Microsoft.AspNet.Routing.Template.Tests
|
|||
|
||||
// Assert
|
||||
Assert.NotNull(match);
|
||||
Assert.Equal(2, match.Values.Count);
|
||||
Assert.Equal("Home", match.Values["controller"]);
|
||||
Assert.Equal("Index", match.Values["action"]);
|
||||
Assert.False(match.Values.ContainsKey("id"));
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче