Index: modules/filter/filter.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/filter/filter.module,v
retrieving revision 1.343
diff -u -p -r1.343 filter.module
--- modules/filter/filter.module	11 Sep 2010 03:30:03 -0000	1.343
+++ modules/filter/filter.module	14 Sep 2010 21:08:27 -0000
@@ -873,6 +873,16 @@ function filter_process_format($element)
       }
     }
   }
+  // Additionally account for the case when a content was stored with a text
+  // format that no longer exists. In this case, we need to inject an empty
+  // option to ensure that the user's user agent does not blatantly reset the
+  // content's text format to the first available (as #default_value is not in
+  // #options) and validate that the user actually chose a text format manually.
+  elseif (!isset($all_formats[$element['#format']])) {
+    $element['format']['format']['#options'] = array(0 => t('<Please select>')) + $element['format']['format']['#options'];
+    $element['format']['format']['#default_value'] = 0;
+    $element['format']['format']['#element_validate'][] = 'filter_form_element_validate_format';
+  }
 
   return $element;
 }
@@ -894,6 +904,17 @@ function filter_form_access_denied($elem
 }
 
 /**
+ * Form element validation handler for the text format select list.
+ *
+ * @see filter_process_format()
+ */
+function filter_form_element_validate_format(&$element, &$form_state) {
+  if (empty($element['#value'])) {
+    form_error($element, t('!name field is required.', array('!name' => $elements['#title'])));
+  }
+}
+
+/**
  * Returns HTML for a text format-enabled form element.
  *
  * @param $variables
