FoundatioFx / Foundatio.Parsers

A lucene style query parser that is extensible and allows modifying the query.
https://www.nuget.org/packages/Foundatio.Parsers.LuceneQueries/
Apache License 2.0
66 stars 19 forks source link

ElasticQueryParser ParseAsync does not throw exception for query with odd number of quotation marks. #62

Closed Issung closed 3 years ago

Issung commented 3 years ago

We are using ElasticQueryParser's ParseAsync to check if a query string is valid, if it throws then we know it is not. Though the parser does not throw for a string with an odd number of quotation marks, e.g. "MyFile. But when the query is sent off to Elastic Search a 500 error returns. This method to check for other issues such as the search string test + other (which is invalid), among other tests do throw exceptions, but it seems to not catch these odd quotation mark errors, meaning that at the moment we are currently counting the amount of quotation marks and escaping them if odd manually, rather than just relying on the parser to catch that invalid syntax for us.

ElasticQueryVisitorContext Context = new ElasticQueryVisitorContext { QueryType = QueryType.Query, DefaultOperator = GroupOperator.Default };

ElasticQueryParser parser = new ElasticQueryParser(conf =>
  conf.UseValidation(info => Task.FromResult(ValidateQueryInfo(info)))
);

try
{
  IQueryNode queryNode = await parser.ParseAsync(query, Context);
}
catch (Exception ex)
{
  return false;
}

Let me know if you need anymore info!

niemyjski commented 3 years ago

Thanks for reaching out. Would you mind submitting a pr with a failing unit test for this, it would be a huge help.

Issung commented 3 years ago

No problem, PR is up: https://github.com/FoundatioFx/Foundatio.Parsers/pull/63.