Menu

#2862 Bad Theme Name Logic

Development CVS
closed-fixed
None
5
2022-02-28
2022-02-15
No

Updated to PHP 8.1, which now throws some warnings when functions that expect a string receive null, and found this:
Development Branch 1.5/functions/page_header.php - line 98

$used_theme = !isset($chosen_theme) && $user_theme_default != 'none' && is_dir($chosen_theme) && is_readable($chosen_theme)?  $user_themes[$user_theme_default]['PATH'].'/default.css' : $chosen_theme_path;

I'm guessing it should either be isset($chosen_theme) or !empty($chosen_theme)? Otherwise, you're checking to see if the variable's unset, then using the unset variable in is_dir() and is_readable().

Discussion

  • Andrew Sachen

    Andrew Sachen - 2022-02-15

    Upon further investigation, my suggestion is a slightly more complex variable assignment. Something along the lines of:

    if (isset($chosen_theme) && !empty($chosen_theme) && is_dir($chosen_theme) && is_readable($chosen_theme))
        $used_theme = $chosen_theme_path;
    else
        $used_theme = ($user_theme_default == 'none') ? 'none' : $user_themes[$user_theme_default]['PATH'];
    

    The 'default.css' value appended to the path shouldn't be there, as $used_theme is a directory, not a file.

    Also, just below this section of code (where the variable is actually put to use - as a directory path), it looks like there's a leftover double-'none' check with a FIXME on the redundant check.

     
  • Paul Lesniewski

    Paul Lesniewski - 2022-02-28
    • status: open --> closed-fixed
     
  • Paul Lesniewski

    Paul Lesniewski - 2022-02-28

    Thanks for finding this. Combined with the code just below that line, it's all terribly convoluted, but should now be fixed enough not to cause warnings.

     

Log in to post a comment.