Skip to content

Commit

Permalink
Addressed comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
adityasa committed Aug 29, 2023
1 parent e02ace7 commit ea3ad13
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 12 deletions.
19 changes: 9 additions & 10 deletions Microsoft.Azure.Cosmos/src/Query/Core/Parser/CstToAstVisitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -961,36 +961,35 @@ private static string GetStringValueFromNode(IParseTree parseTree)
// https://learn.microsoft.com/en-us/azure/cosmos-db/nosql/query/constants#remarks
// However that's failing in the parser (before reaching this point) and will be fixed separately (after checking server's behavior).
StringBuilder stringBuilder = new StringBuilder(text.Length);
for (int i = 1; i < text.Length - 1; i++)
for (int index = 1; index < text.Length - 1; index++)
{
switch (text[i])
switch (text[index])
{
case '\\':
if ((i + 1) < (text.Length - 1))
if ((index + 1) < (text.Length - 1))
{
switch (text[i + 1])
switch (text[index + 1])
{
case '"':
case '\\':
case '/':
stringBuilder.Append(text[i + 1]);
i++;
stringBuilder.Append(text[index + 1]);
index++;
break;
default:
stringBuilder.Append(text[i]);
stringBuilder.Append(text[index]);
break;
}
}
break;

default:
stringBuilder.Append(text[i]);
stringBuilder.Append(text[index]);
break;
}
}

string unescapedString = stringBuilder.ToString();
return unescapedString;
return stringBuilder.ToString();
}

private static Number64 GetNumber64ValueFromNode(IParseTree parseTree)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@ public void ExecuteTestSuite(IEnumerable<TInput> inputs, [CallerMemberName] stri

Assert.IsTrue(
matched,
$@" Baseline File {baselinePath},
Output File {outputPath},
$@" Baseline File {Path.GetFullPath(baselinePath)},
Output File {Path.GetFullPath(outputPath)},
Expected: {baselineTextSuffix},
Actual: {outputTextSuffix}");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,22 @@
<ParsedQuery><![CDATA[SELECT VALUE ["'SingleQuote", "\"DoubleQuote", "\\ReverseSolidus", "/solidus", "\\bBackspace", "\\fSeparatorFeed", "\\nLineFeed", "\\rCarriageReturn", "\\tTab", "\\u1234"]]]></ParsedQuery>
</Output>
</Result>
<Result>
<Input>
<Description><![CDATA[Single quoted string literals special cases]]></Description>
<Query><![CDATA[SELECT VALUE ['\"', '\"\"', '\\', '\\\\', '\/', '\/\/', '\b', '\b\b', '\f', '\f\f', '\n', '\n\n', '\r', '\r\r', '\t', '\t\t', '\u1234', '\u1234\u1234']]]></Query>
</Input>
<Output>
<ParsedQuery><![CDATA[SELECT VALUE ["\"", "\"\"", "\\", "\\\\", "/", "//", "\\b", "\\b\\b", "\\f", "\\f\\f", "\\n", "\\n\\n", "\\r", "\\r\\r", "\\t", "\\t\\t", "\\u1234", "\\u1234\\u1234"]]]></ParsedQuery>
</Output>
</Result>
<Result>
<Input>
<Description><![CDATA[Double quoted string literals special cases]]></Description>
<Query><![CDATA[SELECT VALUE ["\"", "\"\"", "\\", "\\\\", "\/", "\/\/", "\b", "\b\b", "\f", "\f\f", "\n", "\n\n", "\r", "\r\r", "\t", "\t\t", "\u1234", "\u1234\u1234"]]]></Query>
</Input>
<Output>
<ParsedQuery><![CDATA[SELECT VALUE ["\"", "\"\"", "\\", "\\\\", "/", "//", "\\b", "\\b\\b", "\\f", "\\f\\f", "\\n", "\\n\\n", "\\r", "\\r\\r", "\\t", "\\t\\t", "\\u1234", "\\u1234\\u1234"]]]></ParsedQuery>
</Output>
</Result>
</Results>
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,12 @@ public void StringLiteral()
CreateInput(
description: @"Double quoted string literals with escape seqence",
scalarExpression: @"[""'SingleQuote"", ""\""DoubleQuote"", ""\\ReverseSolidus"", ""\/solidus"", ""\bBackspace"", ""\fSeparatorFeed"", ""\nLineFeed"", ""\rCarriageReturn"", ""\tTab"", ""\u1234""]"),
CreateInput(
description: @"Single quoted string literals special cases",
scalarExpression: @"['\""', '\""\""', '\\', '\\\\', '\/', '\/\/', '\b', '\b\b', '\f', '\f\f', '\n', '\n\n', '\r', '\r\r', '\t', '\t\t', '\u1234', '\u1234\u1234']"),
CreateInput(
description: @"Double quoted string literals special cases",
scalarExpression: @"[""\"""", ""\""\"""", ""\\"", ""\\\\"", ""\/"", ""\/\/"", ""\b"", ""\b\b"", ""\f"", ""\f\f"", ""\n"", ""\n\n"", ""\r"", ""\r\r"", ""\t"", ""\t\t"", ""\u1234"", ""\u1234\u1234""]"),
};

this.ExecuteTestSuite(inputs);
Expand Down

0 comments on commit ea3ad13

Please sign in to comment.