Skip to content

Commit 96f69fa

Browse files
committed
Eval ParseToArray in OurQuery to handle invalid queries gracefully
This is consistent with RT, so we can show error messages like "Incomplete query" on search page, instead of a fatal error page.
1 parent ce5df94 commit 96f69fa

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

lib/RT/IR.pm

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -502,8 +502,15 @@ sub OurQuery {
502502
my $query = shift;
503503

504504
my ($has_our, $has_other, @lifecycles) = (0, 0);
505+
# ParseToArray dies on invalid SQL; treat unparseable queries as non-RTIR.
506+
my $array;
507+
eval { $array = RT::SQL::ParseToArray( $query ) };
508+
if ( $@ ) {
509+
RT->Logger->warning("OurQuery: failed to parse query '$query': $@");
510+
return;
511+
}
505512
$ticket_sql_parser->walk(
506-
RT::SQL::ParseToArray( $query ),
513+
$array,
507514
{ operand => sub {
508515
return undef unless $_[0]->{'key'} =~ /^(Queue(?:\z|\.)|Lifecycle)/;
509516
my $key = $1;

0 commit comments

Comments
 (0)