? regression.patch
? square-one.patch
? sites/default/files
? sites/default/settings.php
Index: includes/common.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/common.inc,v
retrieving revision 1.925
diff -u -p -r1.925 common.inc
--- includes/common.inc	18 Jun 2009 21:19:01 -0000	1.925
+++ includes/common.inc	27 Jun 2009 10:32:35 -0000
@@ -362,6 +362,11 @@ function drupal_not_found() {
 
   watchdog('page not found', check_plain($_GET['q']), NULL, WATCHDOG_WARNING);
 
+  // Keep old path for reference.
+  if (!isset($_REQUEST['destination'])) {
+    $_REQUEST['destination'] = $_GET['q'];
+  }
+
   $path = drupal_get_normal_path(variable_get('site_404', ''));
   if ($path && $path != $_GET['q']) {
     // Custom 404 handler. Set the active item in case there are tabs to
@@ -389,9 +394,13 @@ function drupal_not_found() {
  */
 function drupal_access_denied() {
   drupal_set_header('403 Forbidden');
-
   watchdog('access denied', check_plain($_GET['q']), NULL, WATCHDOG_WARNING);
 
+  // Keep old path for reference.
+  if (!isset($_REQUEST['destination'])) {
+    $_REQUEST['destination'] = $_GET['q'];
+  }
+
   $path = drupal_get_normal_path(variable_get('site_403', ''));
   if ($path && $path != $_GET['q']) {
     // Custom 403 handler. Set the active item in case there are tabs to
Index: modules/search/search.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/search/search.module,v
retrieving revision 1.298
diff -u -p -r1.298 search.module
--- modules/search/search.module	3 Jun 2009 06:52:29 -0000	1.298
+++ modules/search/search.module	27 Jun 2009 10:32:41 -0000
@@ -1118,6 +1118,12 @@ function search_box(&$form_state, $form_
  * Process a block search form submission.
  */
 function search_box_form_submit($form, &$form_state) {
+  // The search form relies on control of the redirect destination for its
+  // functionality, so we override any static destination set in the request.
+  if (isset($_REQUEST['destination'])) {
+    unset($_REQUEST['destination']);
+  }
+
   $form_id = $form['form_id']['#value'];
   $form_state['redirect'] = 'search/node/' . trim($form_state['values'][$form_id]);
 }
Index: modules/system/system.test
===================================================================
RCS file: /cvs/drupal/drupal/modules/system/system.test,v
retrieving revision 1.50
diff -u -p -r1.50 system.test
--- modules/system/system.test	13 Jun 2009 21:08:31 -0000	1.50
+++ modules/system/system.test	27 Jun 2009 10:32:42 -0000
@@ -508,7 +508,7 @@ class AccessDeniedTestCase extends Drupa
     parent::setUp();
 
     // Create an administrative user.
-    $this->admin_user = $this->drupalCreateUser(array('administer site configuration'));
+    $this->admin_user = $this->drupalCreateUser(array('administer site configuration', 'administer blocks'));
     $this->drupalLogin($this->admin_user);
   }
 
@@ -545,6 +545,22 @@ class AccessDeniedTestCase extends Drupa
     $this->drupalGet('admin');
     $this->assertText(t('Access denied'), t('Found the default 403 page'));
     $this->assertText(t('User login'), t('Blocks are shown on the default 403 page'));
+
+    // Log back in, set the custom 403 page to /user and remove the block
+    $this->drupalLogin($this->admin_user);
+    variable_set('site_403', 'user');
+    $this->drupalPost('admin/build/block', array('user_login[region]' => '-1'), t('Save blocks'));
+
+    // Check that we can log in from the 403 page.
+    $this->drupalLogout();
+    $edit = array(
+      'name' => $this->admin_user->name,
+      'pass' => $this->admin_user->pass_raw,
+    );
+    $this->drupalPost('admin/settings/site-information', $edit, t('Log in'));
+
+    // Check that we're still on the same page.
+    $this->assertText(t('Site information'));
   }
 }
 
