Index: modules/user/user.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/user/user.module,v
retrieving revision 1.963
diff -u -p -r1.963 user.module
--- modules/user/user.module	9 Feb 2009 07:36:15 -0000	1.963
+++ modules/user/user.module	9 Feb 2009 17:57:38 -0000
@@ -1284,7 +1284,7 @@ function user_menu() {
     'type' => MENU_CALLBACK,
   );
 
-  $items['user/%user/edit'] = array(
+  $items['user/%user_category/edit'] = array(
     'title' => 'Edit',
     'page callback' => 'user_edit',
     'page arguments' => array(1),
@@ -1342,7 +1342,7 @@ function user_category_load($uid, &$map,
     $accounts[$uid] = user_load($uid);
   }
   $valid = TRUE;
-  if ($account = $accounts[$uid]) {
+  if (($account = $accounts[$uid]) && isset($map[$index + 1]) && $map[$index + 1] == 'edit') {
     // Since the path is like user/%/edit/category_name, the category name will
     // be at a position 2 beyond the index corresponding to the % wildcard.
     $category_index = $index + 2;
Index: modules/user/user.test
===================================================================
RCS file: /cvs/drupal/drupal/modules/user/user.test,v
retrieving revision 1.28
diff -u -p -r1.28 user.test
--- modules/user/user.test	9 Feb 2009 07:36:15 -0000	1.28
+++ modules/user/user.test	9 Feb 2009 17:57:39 -0000
@@ -963,3 +963,31 @@ class UserBlocksUnitTests extends Drupal
     $this->assertEqual(db_query("SELECT COUNT(*) FROM {sessions} WHERE uid = :uid AND sid = :sid AND timestamp = :timestamp", array(':uid' => $fields['uid'], ':sid' => $fields['sid'], ':timestamp' => $fields['timestamp']))->fetchField(), 1, t('Session record inserted.'));
   }
 }
+
+class UserTestPaths extends DrupalWebTestCase {
+  function getInfo() {
+    return array(
+      'name' => 'Test profile path handling',
+      'description' => t('Test handling of profile categories and paths.') ,
+      'group' => t('User'));
+  }
+  function setUp() {
+    parent::setUp();
+
+    $this->admin_user = $this->drupalCreateUser(array('administer users', 'access user profiles'));
+
+    // This is the user whose profile will be edited.
+    $this->normal_user = $this->drupalCreateUser();
+  }
+
+  /**
+   * Test profile path handling.
+   */
+  function testProfileEditPath() {
+    $this->drupalLogin($this->admin_user);
+
+    // Check that an invalid category returns a 404.
+    $this->drupalGet('user/' . $this->admin_user->uid . '/edit/invalid');
+    $this->assertResponse(404, t('An invalid profile category produces a 404.'));
+  }
+}
