Skip to content

Commit cc56f3e

Browse files
authored
Merge pull request #369 from iMattPro/fixes
Improve route matching
2 parents fe38a1d + 68adb38 commit cc56f3e

2 files changed

Lines changed: 65 additions & 2 deletions

File tree

‎event/listener.php‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,11 @@ public function add_permission($event)
131131
*/
132132
public function viewonline_page($event)
133133
{
134+
if (!isset($event['row']['session_page']))
135+
{
136+
return;
137+
}
138+
134139
$session_path = parse_url($event['row']['session_page'], PHP_URL_PATH);
135140
if (!is_string($session_path))
136141
{
@@ -145,12 +150,12 @@ public function viewonline_page($event)
145150
{
146151
$route = $this->router->match($session_path);
147152
}
148-
catch (\Symfony\Component\Routing\Exception\ExceptionInterface $e)
153+
catch (\RuntimeException $e)
149154
{
150155
return;
151156
}
152157

153-
if ($route['_route'] === 'phpbb_boardrules_main_controller')
158+
if (isset($route['_route']) && $route['_route'] === 'phpbb_boardrules_main_controller')
154159
{
155160
$event['location'] = $this->lang->lang('BOARDRULES_VIEWONLINE');
156161
$event['location_url'] = $this->controller_helper->route('phpbb_boardrules_main_controller');

‎tests/event/listener_test.php‎

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,14 @@ protected function setUp(): void
7070
{
7171
return array('_route' => 'phpbb_boardrules_main_controller');
7272
}
73+
else if ($path === '/runtime-error')
74+
{
75+
throw new \RuntimeException('Unable to match route.');
76+
}
77+
else if ($path === '/missing-route-name')
78+
{
79+
return array();
80+
}
7381

7482
throw new \Symfony\Component\Routing\Exception\ResourceNotFoundException();
7583
});
@@ -371,6 +379,56 @@ public function viewonline_page_data()
371379
'phpbb_boardrules_main_controller#a:0:{}',
372380
'BOARDRULES_VIEWONLINE',
373381
),
382+
// test when the session page is missing
383+
array(
384+
array(
385+
1 => 'app',
386+
),
387+
array(),
388+
'$location_url',
389+
'$location',
390+
'$location_url',
391+
'$location',
392+
),
393+
// test a non-routing runtime exception is treated as an unmatched page
394+
array(
395+
array(
396+
1 => 'app',
397+
),
398+
array(
399+
'session_page' => 'app.' . $phpEx . '/runtime-error'
400+
),
401+
'$location_url',
402+
'$location',
403+
'$location_url',
404+
'$location',
405+
),
406+
// test a route result without a route name
407+
array(
408+
array(
409+
1 => 'app',
410+
),
411+
array(
412+
'session_page' => 'app.' . $phpEx . '/missing-route-name'
413+
),
414+
'$location_url',
415+
'$location',
416+
'$location_url',
417+
'$location',
418+
),
419+
// test when on_page is index and session_page is NOT for boardrules
420+
array(
421+
array(
422+
1 => 'index',
423+
),
424+
array(
425+
'session_page' => 'index.' . $phpEx . '/foobar'
426+
),
427+
'$location_url',
428+
'$location',
429+
'$location_url',
430+
'$location',
431+
),
374432
// test when the front controller has the phpBB 4 name
375433
array(
376434
array(

0 commit comments

Comments
 (0)