Fix negative route params. Fixes #1437

This commit is contained in:
KristianJakubik 2018-09-23 18:17:42 +01:00 committed by Steve Sanderson
parent 0942b5aa0d
commit 067d245f94
4 changed files with 33 additions and 3 deletions

View File

@ -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;
}

View File

@ -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()
{

View File

@ -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]

View File

@ -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; }
}