Hi!

When validating my website, I noticed that menu items whose path contained a single quote had invalid class names, for example 'menu-path-viewname-What's New'; it's fixable by changing the two lines where this is generated to use backslash-escaped double quote so the above example would become "menu-path-viewname-What's New" which is a correctly terminated string. Changed code is shown below :-

function _nice_menu_tree($pid = 1) { 
  $menu = menu_get_menu(); 
  $output['content'] = ''; 

  $output['subject'] = $menu['items'][$pid]['title'];

  if ($menu['visible'][$pid]['children']) {
    foreach ($menu['visible'][$pid]['children'] as $mid) {
      // Build class name based on menu path e.g. to give each menu item individual style
      $path_class = 'menu-path-'. str_replace('/', '-', $menu['items'][$mid]['path']);
      if (count($menu['visible'][$mid]['children']) > 0) {
        $output['content'].= "<li id='menu-$mid' class=\"menuparent $path_class\">".menu_item_link($mid);
        $output['content'].= "<ul>";
        $tmp = _nice_menu_tree($mid);
        $output['content'].= $tmp['content'];
        $output['content'].= "</ul>";
        $output['content'].= "</li>";
      } 
      else {
        $output['content'].= "<li id='menu-$mid' class=\"$path_class\">".menu_item_link($mid)."</li>";
      }
    }
  }
  return $output;

Pete.

Comments

add1sun’s picture

Status: Active » Patch (to be ported)

This has already been fixed in HEAD and 5 but still needs to be ported back to 4.7

add1sun’s picture

Status: Patch (to be ported) » Fixed

Backported to 4.7.

Anonymous’s picture

Status: Fixed » Closed (fixed)