Skip to content

Commit

Permalink
Merge pull request SimpleMachines#8493 from Sesquipedalian/3.0/board_…
Browse files Browse the repository at this point in the history
…topic_invalid_id_error

[3.0] Fixes issues when URL contains an invalid board or topic ID
  • Loading branch information
Sesquipedalian authored Mar 2, 2025
2 parents f6b3f3f + 080c547 commit 722f92a
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 14 deletions.
2 changes: 1 addition & 1 deletion Sources/Actions/Display.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public function execute(): void
{
// What are you gonna display if this is empty?!
if (empty(Topic::$topic_id)) {
ErrorHandler::fatalLang('no_board', false);
ErrorHandler::fatalLang('not_a_topic', false);
}

$this->checkPrevNextRedirect();
Expand Down
4 changes: 3 additions & 1 deletion Sources/Board.php
Original file line number Diff line number Diff line change
Expand Up @@ -1928,7 +1928,9 @@ public static function parseRoute(array $route, array $params = []): array
$params['action'] = 'messageindex';
array_shift($route);

preg_match('/^(\X*?)(\d+(?:\.\d+)?)$/u', array_shift($route), $matches);
if (!preg_match('/^(\X*?)(\d+(?:\.\d+)?)$/u', array_shift($route), $matches)) {
return $params;
}

$board = $matches[2];

Expand Down
23 changes: 12 additions & 11 deletions Sources/Forum.php
Original file line number Diff line number Diff line change
Expand Up @@ -704,9 +704,18 @@ protected static function findAction(?string $action): string|callable|false
{
// If no action was supplied, is there an implied action?
if (empty($action)) {
// Action and board are both empty... BoardIndex!
if (empty(Board::$info->id) && empty(Topic::$topic_id)) {
// ... unless someone else wants to do something different.
// We check $_GET['topic'] and $_GET['board'] because the implied
// action depends on what was in the URL, not on whatever values we
// calculated for Board::$info->id and Topic::$info->id. This means
// that if $_GET['topic'] or $_GET['board'] are set to something
// invalid, an error will be shown. This is the correct and intended
// behaviour.
if (isset($_GET['topic'])) {
$action = 'display';
} elseif (isset($_GET['board'])) {
$action = 'messageindex';
} else {
// Does a mod want to change the default action?
if (!empty(Config::$modSettings['integrate_default_action'])) {
$default_action = explode(',', Config::$modSettings['integrate_default_action'])[0];

Expand All @@ -715,14 +724,6 @@ protected static function findAction(?string $action): string|callable|false

$action = 'boardindex';
}
// Topic is empty, and action is empty.... MessageIndex!
elseif (empty(Topic::$topic_id)) {
$action = 'messageindex';
}
// Board is not empty... topic is not empty... action is empty... Display!
else {
$action = 'display';
}
}

// Still no valid action?
Expand Down
4 changes: 3 additions & 1 deletion Sources/Topic.php
Original file line number Diff line number Diff line change
Expand Up @@ -1510,7 +1510,9 @@ public static function parseRoute(array $route, array $params = []): array
$params['action'] = 'display';
array_shift($route);

preg_match('/^(\X*?)(\d+(?:\.(?:new|msg\d+|from\d+|\d+))?)$/u', array_shift($route), $matches);
if (!preg_match('/^(\X*?)(\d+(?:\.(?:new|msg\d+|from\d+|\d+))?)$/u', array_shift($route), $matches)) {
return $params;
}

$topic = $matches[2];

Expand Down

0 comments on commit 722f92a

Please sign in to comment.