Index: wp-includes/post.php
===================================================================
--- wp-includes/post.php	(revision 10773)
+++ wp-includes/post.php	(working copy)
@@ -1410,9 +1410,11 @@
 
 	// Create a valid post name.  Drafts and pending posts are allowed to have an empty
 	// post name.
-	if ( empty($post_name) ) {
+	if ( !isset($post_name) || empty($post_name) ) {
 		if ( !in_array( $post_status, array( 'draft', 'pending' ) ) )
 			$post_name = sanitize_title($post_title);
+		else
+			$post_name = '';
 	} else {
 		$post_name = sanitize_title($post_name);
 	}
@@ -1484,20 +1486,8 @@
 	if ( !isset($post_password) || 'private' == $post_status )
 		$post_password = '';
 
-	if ( !in_array( $post_status, array( 'draft', 'pending' ) ) ) {
-		$post_name_check = $wpdb->get_var($wpdb->prepare("SELECT post_name FROM $wpdb->posts WHERE post_name = %s AND post_type = %s AND ID != %d AND post_parent = %d LIMIT 1", $post_name, $post_type, $post_ID, $post_parent));
+	$post_name = wp_unique_slug($post_ID, $post_status, $post_name, $post_type, $post_parent);
 
-		if ($post_name_check || in_array($post_name, $wp_rewrite->feeds) ) {
-			$suffix = 2;
-			do {
-				$alt_post_name = substr($post_name, 0, 200-(strlen($suffix)+1)). "-$suffix";
-				$post_name_check = $wpdb->get_var($wpdb->prepare("SELECT post_name FROM $wpdb->posts WHERE post_name = %s AND post_type = %s AND ID != %d AND post_parent = %d LIMIT 1", $alt_post_name, $post_type, $post_ID, $post_parent));
-				$suffix++;
-			} while ($post_name_check);
-			$post_name = $alt_post_name;
-		}
-	}
-
 	// expected_slashed (everything!)
 	$data = compact( array( 'post_author', 'post_date', 'post_date_gmt', 'post_content', 'post_content_filtered', 'post_title', 'post_excerpt', 'post_status', 'post_type', 'comment_status', 'ping_status', 'post_password', 'post_name', 'to_ping', 'pinged', 'post_modified', 'post_modified_gmt', 'post_parent', 'menu_order', 'guid' ) );
 	$data = apply_filters('wp_insert_post_data', $data, $postarr);
@@ -1705,7 +1695,36 @@
 	return wp_publish_post($post_id);
 }
 
+
 /**
+ * Given the desired slug and some post details computes a unique slug for the post.
+ * 
+ * @param integer $post_ID
+ * @param string $post_status no uniqueness checks are made if the post is still draft or pending
+ * @param string $post_name the desired slug
+ * @param string $post_type
+ * @param integer $post_parent
+ * @return string unique slug for the post, based on $post_name (with a -1, -2, etc. suffix) 
+ */
+function wp_unique_slug($post_ID, $post_status, $post_name, $post_type, $post_parent) {
+	global $wpdb, $wp_rewrite;
+	if ( !in_array( $post_status, array( 'draft', 'pending' ) ) ) {
+		$post_name_check = $wpdb->get_var($wpdb->prepare("SELECT post_name FROM $wpdb->posts WHERE post_name = %s AND post_type = %s AND ID != %d AND post_parent = %d LIMIT 1", $post_name, $post_type, $post_ID, $post_parent));
+
+		if ($post_name_check || in_array($post_name, $wp_rewrite->feeds) ) {
+			$suffix = 2;
+			do {
+				$alt_post_name = substr($post_name, 0, 200-(strlen($suffix)+1)). "-$suffix";
+				$post_name_check = $wpdb->get_var($wpdb->prepare("SELECT post_name FROM $wpdb->posts WHERE post_name = %s AND post_type = %s AND ID != %d AND post_parent = %d LIMIT 1", $alt_post_name, $post_type, $post_ID, $post_parent));
+				$suffix++;
+			} while ($post_name_check);
+			$post_name = $alt_post_name;
+		}
+	}
+	return $post_name;
+}
+
+/**
  * Adds tags to a post.
  *
  * @uses wp_set_post_tags() Same first two parameters, but the last parameter is always set to true.
@@ -3701,4 +3720,4 @@
 
 		add_filter('the_preview', '_set_preview');
 	}
-}
+}
\ No newline at end of file
Index: wp-admin/includes/post.php
===================================================================
--- wp-admin/includes/post.php	(revision 10773)
+++ wp-admin/includes/post.php	(working copy)
@@ -923,6 +923,8 @@
 	if (!is_null($name)) {
 		$post->post_name = sanitize_title($name? $name : $title, $post->ID);
 	}
+	
+	$post->post_name = wp_unique_slug($post->ID, $post->post_status, $post->post_name, $post->post_type, $post->post_parent);	
 
 	$post->filter = 'sample'; 
 
