Skip to content

Commit

Permalink
Query: Fixes Parsing Error in SQL DOM when CultureInfo is available (#…
Browse files Browse the repository at this point in the history
…3832)

* add fix

* Add cultural info to test to verify correct behavior

* address pr review to restore to restore culture

* fix comment

---------

Co-authored-by: Minh Le <[email protected]>
  • Loading branch information
leminh98 and Minh Le authored May 2, 2023
1 parent 20121c8 commit 15616d3
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ namespace Microsoft.Azure.Cosmos.Query.Core.Parser
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Diagnostics.Contracts;
using System.Globalization;
using Antlr4.Runtime.Misc;
using Antlr4.Runtime.Tree;
using Microsoft.Azure.Cosmos.SqlObjects;
Expand Down Expand Up @@ -963,7 +964,7 @@ private static Number64 GetNumber64ValueFromNode(IParseTree parseTree)
}
else
{
number64 = double.Parse(text);
number64 = double.Parse(text, CultureInfo.InvariantCulture);
}

return number64;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
namespace Microsoft.Azure.Cosmos.Tests.Query.Parser
{
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Threading;
using System.Xml;
using Microsoft.Azure.Cosmos.Query.Core.Monads;
using Microsoft.Azure.Cosmos.Query.Core.Parser;
Expand All @@ -17,6 +20,8 @@ public abstract class SqlParserBaselineTests : BaselineTests<SqlParserBaselineTe
{
public override SqlParserBaselineTestOutput ExecuteTest(SqlParserBaselineTestInput input)
{
CultureInfo defaultCulture = Thread.CurrentThread.CurrentCulture;

TryCatch<SqlQuery> parseQueryMonad = SqlQueryParser.Monadic.Parse(input.Query);
if (parseQueryMonad.Succeeded)
{
Expand All @@ -26,6 +31,22 @@ public override SqlParserBaselineTestOutput ExecuteTest(SqlParserBaselineTestInp
Assert.AreEqual(parseQueryMonad.Result, parseQueryMonad2.Result);
}

// Set culture to non-standard (US) to catch any parsing error
foreach (string culture in new List<string> { "en-US", "fr-FR", "jp-JP" })
{
Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo(culture);
TryCatch<SqlQuery> parseQueryMonadCulture = SqlQueryParser.Monadic.Parse(input.Query);
if (parseQueryMonadCulture.Succeeded)
{
// Addtional round trip for extra validation
TryCatch<SqlQuery> parseQueryMonadCulture2 = SqlQueryParser.Monadic.Parse(parseQueryMonad.Result.ToString());
Assert.IsTrue(parseQueryMonadCulture2.Succeeded);
Assert.AreEqual(parseQueryMonadCulture2.Result, parseQueryMonadCulture2.Result);
}
}

// return thread to default culture
Thread.CurrentThread.CurrentCulture = defaultCulture;
return new SqlParserBaselineTestOutput(parseQueryMonad);
}
}
Expand Down

0 comments on commit 15616d3

Please sign in to comment.