Skip to content
代码片段 群组 项目
提交 067d245f 编辑于 作者: KristianJakubik's avatar KristianJakubik 提交者: Steve Sanderson
浏览文件

Fix negative route params. Fixes #1437

上级 0942b5aa
No related branches found
No related tags found
无相关合并请求
// Copyright (c) .NET Foundation. All rights reserved.
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
......@@ -62,10 +62,10 @@ namespace Microsoft.AspNetCore.Blazor.Routing
return new TypeRouteConstraint<Guid>(Guid.TryParse);
case "int":
return new TypeRouteConstraint<int>((string str, out int result)
=> int.TryParse(str, NumberStyles.None, CultureInfo.InvariantCulture, out result));
=> int.TryParse(str, NumberStyles.Integer, CultureInfo.InvariantCulture, out result));
case "long":
return new TypeRouteConstraint<long>((string str, out long result)
=> long.TryParse(str, NumberStyles.None, CultureInfo.InvariantCulture, out result));
=> long.TryParse(str, NumberStyles.Integer, CultureInfo.InvariantCulture, out result));
default:
return null;
}
......
......@@ -61,6 +61,23 @@ namespace Microsoft.AspNetCore.Blazor.E2ETest.Tests
AssertHighlightedLinks();
}
[Fact]
public void CanArriveAtPageWithNumberParameters()
{
var testInt = int.MinValue;
var testLong = long.MinValue;
var testDec = -2.33333m;
var testDouble = -1.489d;
var testFloat = -2.666f;
SetUrlViaPushState($"/WithNumberParameters/{testInt}/{testLong}/{testDouble}/{testFloat}/{testDec}");
var app = MountTestComponent<TestRouter>();
var expected = $"Test parameters: {testInt} {testLong} {testDouble} {testFloat} {testDec}";
Assert.Equal(expected, app.FindElement(By.Id("test-info")).Text);
}
[Fact]
public void CanArriveAtNonDefaultPage()
{
......
......@@ -167,7 +167,9 @@ namespace Microsoft.AspNetCore.Blazor.Test.Routing
new object[] { "/{value:float}", "/0.1", 0.1f },
new object[] { "/{value:guid}", "/1FCEF085-884F-416E-B0A1-71B15F3E206B", Guid.Parse("1FCEF085-884F-416E-B0A1-71B15F3E206B") },
new object[] { "/{value:int}", "/123", 123 },
new object[] { "/{value:int}", "/-123", -123},
new object[] { "/{value:long}", "/9223372036854775807", long.MaxValue },
new object[] { "/{value:long}", $"/-9223372036854775808", long.MinValue },
};
[Theory]
......
@page "/WithNumberParameters/{TestInt:int}/{TestLong:long}/{TestDouble:double}/{TestFloat:float}/{TestDec:decimal}"
<div id="test-info">Test parameters: @TestInt @TestLong @TestDouble @TestFloat @TestDec</div>
@functions
{
[Parameter] int TestInt { get; set; }
[Parameter] long TestLong { get; set; }
[Parameter] double TestDouble { get; set; }
[Parameter] float TestFloat { get; set; }
[Parameter] decimal TestDec { get; set; }
}
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册