Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Query: Fixes Parsing Error in SQL DOM when CultureInfo is available #3832

Merged
5 commits merged into from
May 2, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
leminh98 marked this conversation as resolved.
Show resolved Hide resolved
}

return number64;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
namespace Microsoft.Azure.Cosmos.Tests.Query.Parser
{
using System;
using System.Collections.Generic;
using System.Threading;
using System.Xml;
using Microsoft.Azure.Cosmos.Query.Core.Monads;
using Microsoft.Azure.Cosmos.Query.Core.Parser;
Expand All @@ -26,6 +28,20 @@ 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-EN", "fr-FR", "jp-JP" })
leminh98 marked this conversation as resolved.
Show resolved Hide resolved
{
Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo(culture);
leminh98 marked this conversation as resolved.
Show resolved Hide resolved
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(parseQueryMonad.Result, parseQueryMonadCulture2.Result);
}
leminh98 marked this conversation as resolved.
Show resolved Hide resolved
}

return new SqlParserBaselineTestOutput(parseQueryMonad);
}
}
Expand Down