Index: user.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/user/user.module,v
retrieving revision 1.983
diff -u -p -r1.983 user.module
--- user.module	30 Apr 2009 21:44:19 -0000	1.983
+++ user.module	4 May 2009 22:04:20 -0000
@@ -995,7 +995,6 @@ function user_user_categories($edit, $ac
 
 function user_login_block() {
   $form = array(
-    '#action' => url($_GET['q'], array('query' => drupal_get_destination())),
     '#id' => 'user-login-form',
     '#validate' => user_login_default_validators(),
     '#submit' => array('user_login_submit'),
@@ -1718,7 +1717,7 @@ function user_authenticate_finalize(&$ed
  */
 function user_login_submit($form, &$form_state) {
   global $user;
-  if ($user->uid) {
+  if ($user->uid && $form['#id'] != 'user-login-form') {
     $form_state['redirect'] = 'user/' . $user->uid;
     return;
   }
Index: modules/user/user.test
===================================================================
RCS file: /cvs/drupal/drupal/modules/user/user.test,v
retrieving revision 1.34
diff -u -p -r1.34 user.test
--- modules/user/user.test	25 Apr 2009 17:52:43 -0000	1.34
+++ modules/user/user.test	4 May 2009 22:07:27 -0000
@@ -923,6 +923,30 @@ class UserBlocksUnitTests extends Drupal
  }

  /**
+   * Test the user login block.
+   */
+  function testUserLoginBlock() {
+    // Create a user with some permission that anonymous users lack.
+    $user = $this->drupalCreateUser(array('administer permissions'));
+
+    // Log in using the block.
+    $edit = array();
+    $edit['name'] = $user->name;
+    $edit['pass'] = $user->pass_raw;
+    $this->drupalPost('admin/user/permissions', $edit, t('Log in'));
+    $this->assertText(t('Log out'), t('Logged in.'));
+
+    // Check that we are still on the same page.
+    $this->assertPattern('!<title.*?' . t('Permissions') . '.*?</title>!', t('Still on the same page after login'));
+
+    // Now, log out and repeat with a non-403 page.
+    $this->clickLink(t('Log out'));
+    $this->drupalPost('filter/tips', $edit, t('Log in'));
+    $this->assertText(t('Log out'), t('Logged in.'));
+    $this->assertPattern('!<title.*?' . t('Compose tips') . '.*?</title>!', t('Still on the same page after login'));
+  }
+
+  /**
   * Test the Who's Online block.
   */
  function testWhosOnlineBlock() {
