diff --git a/src/Microsoft.AspNetCore.Blazor/Routing/RouteConstraint.cs b/src/Microsoft.AspNetCore.Blazor/Routing/RouteConstraint.cs index ebce1daecccd2007e2461a212e0c9d9f5ebb10df..db316ecd227f29e0eb935ad9c924509519f38e61 100644 --- a/src/Microsoft.AspNetCore.Blazor/Routing/RouteConstraint.cs +++ b/src/Microsoft.AspNetCore.Blazor/Routing/RouteConstraint.cs @@ -1,4 +1,4 @@ -// 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; } diff --git a/test/Microsoft.AspNetCore.Blazor.E2ETest/Tests/RoutingTest.cs b/test/Microsoft.AspNetCore.Blazor.E2ETest/Tests/RoutingTest.cs index 788feaf3941aee1392e18944722e69c06b87bbfa..f5c8cebdf6de20a48cb91b72ca03168ab13cb664 100644 --- a/test/Microsoft.AspNetCore.Blazor.E2ETest/Tests/RoutingTest.cs +++ b/test/Microsoft.AspNetCore.Blazor.E2ETest/Tests/RoutingTest.cs @@ -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() { diff --git a/test/Microsoft.AspNetCore.Blazor.Test/Routing/RouteTableTests.cs b/test/Microsoft.AspNetCore.Blazor.Test/Routing/RouteTableTests.cs index 60965db0d13467e316d33e124791a8d4e47e02c7..571abd90a3ce1a46a42806848a8414ede42af17b 100644 --- a/test/Microsoft.AspNetCore.Blazor.Test/Routing/RouteTableTests.cs +++ b/test/Microsoft.AspNetCore.Blazor.Test/Routing/RouteTableTests.cs @@ -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] diff --git a/test/testapps/BasicTestApp/RouterTest/WithNumberParameters.cshtml b/test/testapps/BasicTestApp/RouterTest/WithNumberParameters.cshtml new file mode 100644 index 0000000000000000000000000000000000000000..634e2d40c5117b8bb42085a24391988b08c37536 --- /dev/null +++ b/test/testapps/BasicTestApp/RouterTest/WithNumberParameters.cshtml @@ -0,0 +1,11 @@ +@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; } +}