Index: modules/block/block.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/block/block.module,v
retrieving revision 1.297
diff -u -p -r1.297 block.module
--- modules/block/block.module	24 Dec 2007 10:33:39 -0000	1.297
+++ modules/block/block.module	18 Jan 2008 23:39:08 -0000
@@ -235,6 +235,8 @@ function _block_rehash() {
   }
 
   $blocks = array();
+  // Valid region names for the theme.
+  $regions = system_region_list($theme_key);
 
   foreach (module_list() as $module) {
     $module_blocks = module_invoke($module, 'block', 'list');
@@ -265,8 +267,15 @@ function _block_rehash() {
           // do not need to update the database here.
           // Add 'info' to this block.
           $old_blocks[$module][$delta]['info'] = $block['info'];
-          // Set region to none if not enabled.
-          $old_blocks[$module][$delta]['region'] = $old_blocks[$module][$delta]['status'] ? $old_blocks[$module][$delta]['region'] : BLOCK_REGION_NONE;
+          // If the region name does not exist, disable the block and assign it to none.
+          if (!empty($old_blocks[$module][$delta]['region']) && !array_key_exists($old_blocks[$module][$delta]['region'], $regions)) {
+            drupal_set_message(t('Block %info has been disabled because its assigned to an invalid region: %region', array('%info' => $old_blocks[$module][$delta]['info'], '%region' => $old_blocks[$module][$delta]['region'])), 'warning');
+            $old_blocks[$module][$delta]['status'] = 0;
+            $old_blocks[$module][$delta]['region'] = BLOCK_REGION_NONE;
+          }
+          else {
+            $old_blocks[$module][$delta]['region'] = $old_blocks[$module][$delta]['status'] ? $old_blocks[$module][$delta]['region'] : BLOCK_REGION_NONE;
+          }
           // Add this block to the list of blocks we return.
           $blocks[] = $old_blocks[$module][$delta];
           // Remove this block from the list of blocks to be deleted.
