Skip to content

Commit c21cee9

Browse files
committed
Specify culture to int.TryParse #356
1 parent 0fa3195 commit c21cee9

File tree

4 files changed

+8
-4
lines changed

4 files changed

+8
-4
lines changed

src/Microsoft.AspNetCore.HttpOverrides/Internal/IPEndPointParser.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

4+
using System.Globalization;
45
using System.Net;
56

67
namespace Microsoft.AspNetCore.HttpOverrides.Internal
@@ -62,7 +63,7 @@ public static bool TryParse(string addressWithPort, out IPEndPoint endpoint)
6263
if (portPart != null)
6364
{
6465
int port;
65-
if (int.TryParse(portPart, out port))
66+
if (int.TryParse(portPart, NumberStyles.None, CultureInfo.InvariantCulture, out port))
6667
{
6768
endpoint = new IPEndPoint(address, port);
6869
return true;

src/Microsoft.AspNetCore.Rewrite/Internal/ApacheModRewrite/ConditionPatternParser.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

44
using System;
5+
using System.Globalization;
56

67
namespace Microsoft.AspNetCore.Rewrite.Internal.ApacheModRewrite
78
{
@@ -216,7 +217,7 @@ private static bool IsValidActionCondition(ParsedModRewriteInput results)
216217
{
217218
// If the type is an integer, verify operand is actually an int
218219
int res;
219-
if (!int.TryParse(results.Operand, out res))
220+
if (!int.TryParse(results.Operand, NumberStyles.None, CultureInfo.InvariantCulture, out res))
220221
{
221222
return false;
222223
}

src/Microsoft.AspNetCore.Rewrite/Internal/IISUrlRewrite/InputParser.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
using System;
55
using System.Collections.Generic;
6+
using System.Globalization;
67
using Microsoft.AspNetCore.Rewrite.Internal.PatternSegments;
78

89
namespace Microsoft.AspNetCore.Rewrite.Internal.IISUrlRewrite
@@ -181,7 +182,7 @@ private static int GetBackReferenceIndex(ParserContext context)
181182

182183
var res = context.Capture();
183184
int index;
184-
if (!int.TryParse(res, out index))
185+
if (!int.TryParse(res, NumberStyles.None, CultureInfo.InvariantCulture, out index))
185186
{
186187
throw new FormatException(Resources.FormatError_InputParserInvalidInteger(res, context.Index));
187188
}

src/Microsoft.AspNetCore.Rewrite/Internal/IISUrlRewrite/UrlRewriteFileParser.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
using System;
55
using System.Collections.Generic;
6+
using System.Globalization;
67
using System.IO;
78
using System.Linq;
89
using System.Xml.Linq;
@@ -219,7 +220,7 @@ private void ParseUrlAction(XElement urlAction, UrlRewriteRuleBuilder builder, b
219220
break;
220221
case ActionType.CustomResponse:
221222
int statusCode;
222-
if (!int.TryParse(urlAction.Attribute(RewriteTags.StatusCode)?.Value, out statusCode))
223+
if (!int.TryParse(urlAction.Attribute(RewriteTags.StatusCode)?.Value, NumberStyles.None, CultureInfo.InvariantCulture, out statusCode))
223224
{
224225
throw new InvalidUrlRewriteFormatException(urlAction, "A valid status code is required");
225226
}

0 commit comments

Comments
 (0)