From fedda36fb0b063ca520a6065222f0add62d2cf6c Mon Sep 17 00:00:00 2001 From: Matt Friedman Date: Tue, 18 Aug 2026 08:02:27 -0700 Subject: [PATCH] Improve route matching --- event/listener.php | 4 ++-- tests/event/listener_test.php | 22 +++++++++++++++++++++- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/event/listener.php b/event/listener.php index f600a3a..04fec9d 100644 --- a/event/listener.php +++ b/event/listener.php @@ -316,9 +316,9 @@ public function viewonline_ideas($event) try { $route = $this->router->match($session_path); - $in_ideas_pages = strpos($route['_route'], 'phpbb_ideas_') === 0; + $in_ideas_pages = isset($route['_route']) && strpos($route['_route'], 'phpbb_ideas_') === 0; } - catch (\Symfony\Component\Routing\Exception\ExceptionInterface $e) + catch (\RuntimeException $e) { // Not a routed Ideas page. } diff --git a/tests/event/listener_test.php b/tests/event/listener_test.php index e39b00e..612fae9 100644 --- a/tests/event/listener_test.php +++ b/tests/event/listener_test.php @@ -80,7 +80,14 @@ protected function setUp(): void $route_collection->add('phpbb_ideas_post_controller', new \Symfony\Component\Routing\Route('/ideas/post')); $matcher = new \Symfony\Component\Routing\Matcher\UrlMatcher($route_collection, new \Symfony\Component\Routing\RequestContext()); $this->router->method('match') - ->willReturnCallback(array($matcher, 'match')); + ->willReturnCallback(function ($path) use ($matcher) { + if ($path === '/runtime-error') + { + throw new \RuntimeException('Unable to match route.'); + } + + return $matcher->match($path); + }); $this->template = $this->getMockBuilder('\phpbb\template\template') ->getMock(); $this->user = new \phpbb\user($this->lang, '\phpbb\datetime'); @@ -429,6 +436,19 @@ public function viewonline_data() 'phpbb_ideas_index_controller#a:0:{}', 'VIEWING_IDEAS', ), + // test a non-routing runtime exception is treated as an unmatched page + array( + array( + 1 => 'index', + ), + array( + 'session_page' => 'index.' . $phpEx . '/runtime-error' + ), + '$location_url', + '$location', + '$location_url', + '$location', + ), // test when viewing an idea topic (any topic in forum id 2) array( array(