Skip to content

Commit

Permalink
Handle "com_" component name as empty
Browse files Browse the repository at this point in the history
A component named "com_" (and nothing else after) is an invalid name.
  • Loading branch information
pascal-meunier authored and erichhuebner committed Jul 15, 2021
1 parent a2727a9 commit 256a395
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions core/libraries/Hubzero/Component/Loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,21 @@ public function canonical($option)
}
// do not allow dots in component name to avoid directory traversal issues
$option = preg_replace('/[^A-Z0-9_-]/i', '', $option);
// prepend com_ to the name if it doesn't start with com_
// if option became empty due to the filtering, return an empty string
if ((strlen($option) > 0) && (substr($option, 0, strlen('com_')) != 'com_'))
if (strlen($option) > 0)
{
$option = 'com_' . $option;
if (substr($option, 0, strlen('com_')) == 'com_')
{
// if option is just the prefix, make it empty because it's invalid
if ($option == 'com_')
{
$option = '';
}
// else it's presumably a good name and return that
} else {
// prepend com_ to the name if it doesn't start with com_
$option = 'com_' . $option;
}
}
return $option;
}
Expand Down

0 comments on commit 256a395

Please sign in to comment.