Skip to content

Commit 2553508

Browse files
committed
Add CultureInfo.InvariantCulture in the TryParse's in CreateAny.
1 parent f1864c6 commit 2553508

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

src/Microsoft.OpenApi.Readers/ParseNodes/ValueNode.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
// Licensed under the MIT license.
33

44
using System;
5+
using System.Globalization;
56
using Microsoft.OpenApi.Any;
6-
using Microsoft.OpenApi.Exceptions;
77
using Microsoft.OpenApi.Readers.Exceptions;
88
using SharpYaml.Serialization;
99

@@ -52,28 +52,28 @@ public override IOpenApiAny CreateAny()
5252
return new OpenApiBoolean(false);
5353
}
5454

55-
if (int.TryParse(value, out var intValue))
55+
if (int.TryParse(value, NumberStyles.None, CultureInfo.InvariantCulture, out var intValue))
5656
{
5757
return new OpenApiInteger(intValue);
5858
}
5959

60-
if (long.TryParse(value, out var longValue))
60+
if (long.TryParse(value, NumberStyles.None, CultureInfo.InvariantCulture, out var longValue))
6161
{
6262
return
6363
new OpenApiLong(
6464
longValue);
6565
}
6666

67-
if (double.TryParse(value, out var dblValue))
67+
if (double.TryParse(value, NumberStyles.None, CultureInfo.InvariantCulture, out var doubleValue))
6868
{
6969
return
7070
new OpenApiDouble(
71-
dblValue); // Note(darrmi): This may be better as decimal. Further investigation required.
71+
doubleValue); // Note(darrmi): This may be better as decimal. Further investigation required.
7272
}
7373

74-
if (DateTimeOffset.TryParse(value, out var datetimeValue))
74+
if (DateTimeOffset.TryParse(value, CultureInfo.InvariantCulture, DateTimeStyles.None, out var dateTimeValue))
7575
{
76-
return new OpenApiDateTime(datetimeValue);
76+
return new OpenApiDateTime(dateTimeValue);
7777
}
7878

7979
// if we can't identify the type of value, return it as string.

test/Microsoft.OpenApi.Readers.Tests/V2Tests/OpenApiDocumentTests.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
using System.Globalization;
66
using System.Threading;
77
using FluentAssertions;
8+
using Microsoft.OpenApi.Any;
89
using Microsoft.OpenApi.Exceptions;
910
using Microsoft.OpenApi.Models;
10-
using Microsoft.OpenApi.Readers.Exceptions;
1111
using Xunit;
1212

1313
namespace Microsoft.OpenApi.Readers.Tests.V2Tests
@@ -86,6 +86,7 @@ public void ParseDocumentWithDifferentCultureShouldSucceed(string culture)
8686
info:
8787
title: Simple Document
8888
version: 0.9.1
89+
x-extension: 2.335
8990
definitions:
9091
sampleSchema:
9192
type: object
@@ -105,7 +106,11 @@ public void ParseDocumentWithDifferentCultureShouldSucceed(string culture)
105106
Info = new OpenApiInfo
106107
{
107108
Title = "Simple Document",
108-
Version = "0.9.1"
109+
Version = "0.9.1",
110+
Extensions =
111+
{
112+
["x-extension"] = new OpenApiDouble(2.335)
113+
}
109114
},
110115
Components = new OpenApiComponents()
111116
{

0 commit comments

Comments
 (0)