Skip to content

Commit

Permalink
FDB: fix error when parsing incomplete variable in FQL expression
Browse files Browse the repository at this point in the history
  • Loading branch information
KrzysFR committed Dec 10, 2024
1 parent 0faaf95 commit 48a6d30
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions FoundationDB.Client/Query/FqlQueryParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ private static string ReadName(ref ReadOnlySpan<char> text)
}

/// <summary>Reads an decodes a variable</summary>
private static (FqlVariableTypes Types, string? Name) ReadVariable(ref ReadOnlySpan<char> text)
private static Maybe<(FqlVariableTypes Types, string? Name)> ReadVariable(ref ReadOnlySpan<char> text)
{
// note: the called has already consumed the leading '<'

Expand All @@ -395,7 +395,7 @@ private static (FqlVariableTypes Types, string? Name) ReadVariable(ref ReadOnlyS
var type = FqlTupleItem.ParseVariableTypeLiteral(text[..p]);
if (type == FqlVariableTypes.None)
{
throw new FormatException($"Invalid variable type '{text[..p]}'");
return new FormatException($"Invalid variable type '{text[..p]}'");
}
types |= type;

Expand All @@ -409,7 +409,7 @@ private static (FqlVariableTypes Types, string? Name) ReadVariable(ref ReadOnlyS
text = text[(p + 1)..];
}

throw new FormatException("Truncated variable");
return new FormatException("Truncated variable");
}

private static bool CouldBeUuid(ReadOnlySpan<char> text) => text.Length >= 36 && text[8] == '-' && text[13] == '-' && text[18] == '-' && text[23] == '-';
Expand Down Expand Up @@ -616,8 +616,11 @@ private static Maybe<FqlTupleExpression> ReadTuple(ref ReadOnlySpan<char> text)
{ // variable

text = text[1..];
var (types, name) = ReadVariable(ref text);
tuple.Var(types, name);
if (!ReadVariable(ref text).Check(out var res, out var error))
{
return error;
}
tuple.Var(res.Types, res.Name);
continue;
}
case ',':
Expand Down

0 comments on commit 48a6d30

Please sign in to comment.