? form.patch
Index: form.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/form.inc,v
retrieving revision 1.324
diff -u -p -r1.324 form.inc
--- form.inc	14 Mar 2009 20:13:26 -0000	1.324
+++ form.inc	26 Mar 2009 18:31:54 -0000
@@ -1498,9 +1498,9 @@ function form_select_options($element, $
   $value_is_array = is_array($element['#value']);
   $options = '';
   foreach ($choices as $key => $choice) {
-    if (is_array($choice)) {
+    if (is_array($choice) && count(element_children($choice))) {
       $options .= '<optgroup label="' . $key . '">';
-      $options .= form_select_options($element, $choice);
+      $options .= form_select_options($element, element_children($choice));
       $options .= '</optgroup>';
     }
     elseif (is_object($choice)) {
@@ -1514,7 +1514,16 @@ function form_select_options($element, $
       else {
         $selected = '';
       }
-      $options .= '<option value="' . check_plain($key) . '"' . $selected . '>' . check_plain($choice) . '</option>';
+      if (is_array($choice)) {
+        $value = check_plain($choice['#value']);
+        if ($choice['#attributes']) {
+          $opt_attr = $choice['#attributes'];
+        }
+      }
+      else {
+        $value = check_plain($choice);
+      }
+      $options .= '<option value="'. check_plain($key) .'"'. $selected .' '. drupal_attributes($opt_attr).'>'. $value .'</option>';
     }
   }
   return $options;
