From f8f4b9f1be84b54bedf8cf36a1c6a4ede89b362c Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Sun, 25 Oct 2020 17:50:00 +0100 Subject: fix HTTP 500 on invalid via RE; improve via handling while at it --- lib/DBInfoscreen/Controller/Stationboard.pm | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/lib/DBInfoscreen/Controller/Stationboard.pm b/lib/DBInfoscreen/Controller/Stationboard.pm index c6f697f..715f33a 100644 --- a/lib/DBInfoscreen/Controller/Stationboard.pm +++ b/lib/DBInfoscreen/Controller/Stationboard.pm @@ -90,10 +90,26 @@ sub result_has_via { my @route = $result->route_post; - if ( List::MoreUtils::any { m{$via}i } @route ) { + my $eq_result = List::MoreUtils::any { lc eq lc($via) } @route; + + if ($eq_result) { return 1; } - return 0; + + my ( $re1_result, $re2_result ); + + eval { + $re2_result = List::MoreUtils::any { m{\Q$via\E}i } @route; + }; + eval { + $re1_result = List::MoreUtils::any { m{$via}i } @route; + }; + + if ($@) { + return $re2_result || $eq_result; + } + + return $re1_result || $re2_result || $eq_result; } sub log_api_access { -- cgit v1.2.3