Fix negative route params. Fixes #1437
This commit is contained in:
parent
0942b5aa0d
commit
067d245f94
|
|
@ -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.
|
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
|
@ -62,10 +62,10 @@ namespace Microsoft.AspNetCore.Blazor.Routing
|
||||||
return new TypeRouteConstraint<Guid>(Guid.TryParse);
|
return new TypeRouteConstraint<Guid>(Guid.TryParse);
|
||||||
case "int":
|
case "int":
|
||||||
return new TypeRouteConstraint<int>((string str, out int result)
|
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":
|
case "long":
|
||||||
return new TypeRouteConstraint<long>((string str, out long result)
|
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:
|
default:
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -61,6 +61,23 @@ namespace Microsoft.AspNetCore.Blazor.E2ETest.Tests
|
||||||
AssertHighlightedLinks();
|
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]
|
[Fact]
|
||||||
public void CanArriveAtNonDefaultPage()
|
public void CanArriveAtNonDefaultPage()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -167,7 +167,9 @@ namespace Microsoft.AspNetCore.Blazor.Test.Routing
|
||||||
new object[] { "/{value:float}", "/0.1", 0.1f },
|
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: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:int}", "/-123", -123},
|
||||||
new object[] { "/{value:long}", "/9223372036854775807", long.MaxValue },
|
new object[] { "/{value:long}", "/9223372036854775807", long.MaxValue },
|
||||||
|
new object[] { "/{value:long}", $"/-9223372036854775808", long.MinValue },
|
||||||
};
|
};
|
||||||
|
|
||||||
[Theory]
|
[Theory]
|
||||||
|
|
|
||||||
|
|
@ -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; }
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue