Index: src/wp-includes/taxonomy.php
===================================================================
--- src/wp-includes/taxonomy.php	(revision 28732)
+++ src/wp-includes/taxonomy.php	(working copy)
@@ -2436,7 +2436,13 @@
 
 	$slug_provided = ! empty( $args['slug'] );
 	if ( ! $slug_provided ) {
-		$slug = sanitize_title($name);
+		$_name = trim( $name );
+		$existing_term = get_term_by( 'name', $_name, $taxonomy );
+		if ( $existing_term ) {
+			$slug = $existing_term->slug;
+		} else {
+			$slug = sanitize_title( $name );
+		}
 	} else {
 		$slug = $args['slug'];
 	}
Index: tests/phpunit/tests/taxonomy.php
===================================================================
--- tests/phpunit/tests/taxonomy.php	(revision 28732)
+++ tests/phpunit/tests/taxonomy.php	(working copy)
@@ -232,4 +232,66 @@
 		);
 		$this->assertEquals( 0, wp_insert_category( $cat, false ) );
 	}
+
+	/**
+	 * @ticket 17689
+	 */
+	function test_duplicate_name() {
+		$term = $this->factory->tag->create_and_get( array( 'name' => 'Bozo' ) );
+		$this->assertFalse( is_wp_error( $term ) );
+		$this->assertTrue( empty( $term->errors ) );
+
+		// Test existing term name with unique slug
+		$term1 = $this->factory->tag->create( array( 'name' => 'Bozo', 'slug' => 'bozo1' ) );
+		$this->assertFalse( is_wp_error( $term1 ) );
+		$this->assertTrue( empty($term1->errors ) );
+
+		// Test an existing term name
+		$term2 = $this->factory->tag->create( array( 'name' => 'Bozo' ) );
+		$this->assertTrue( is_wp_error( $term2 ) );
+		$this->assertNotEmpty( $term2->errors );
+
+		// Test named terms ending in special characters
+		$term3 = $this->factory->tag->create( array( 'name' => 'T$' ) );
+		$term4 = $this->factory->tag->create( array( 'name' => 'T$$' ) );
+		$term5 = $this->factory->tag->create( array( 'name' => 'T$$$' ) );
+		$term6 = $this->factory->tag->create( array( 'name' => 'T$$$$' ) );
+		$term7 = $this->factory->tag->create( array( 'name' => 'T$$$$' ) );
+		$this->assertTrue( is_wp_error( $term7 ) );
+		$this->assertNotEmpty( $term7->errors );
+		$this->assertEquals( $term6, $term7->error_data['term_exists'] );
+
+		$terms = array_map( 'get_tag', array( $term3, $term4, $term5, $term6 ) );
+		$this->assertCount( 4, array_unique( wp_list_pluck( $terms, 'slug' ) ) );
+
+		// Test named terms with only special characters
+		$term8 = $this->factory->tag->create( array( 'name' => '$' ) );
+		$term9 = $this->factory->tag->create( array( 'name' => '$$' ) );
+		$term10 = $this->factory->tag->create( array( 'name' => '$$$' ) );
+		$term11 = $this->factory->tag->create( array( 'name' => '$$$$' ) );
+		$term12 = $this->factory->tag->create( array( 'name' => '$$$$' ) );
+		$this->assertTrue( is_wp_error( $term12 ) );
+		$this->assertNotEmpty( $term12->errors );
+		$this->assertEquals( $term11, $term12->error_data['term_exists'] );
+
+		$terms = array_map( 'get_tag', array( $term8, $term9, $term10, $term11 ) );
+		$this->assertCount( 4, array_unique( wp_list_pluck( $terms, 'slug' ) ) );
+
+		$term13 = $this->factory->tag->create( array( 'name' => 'A' ) );
+		$this->assertFalse( is_wp_error( $term13 ) );
+		$term14 = $this->factory->tag->create( array( 'name' => 'A' ) );
+		$this->assertTrue( is_wp_error( $term14 ) );
+		$term15 = $this->factory->tag->create( array( 'name' => 'A+', 'slug' => 'a' ) );
+		$this->assertFalse( is_wp_error( $term15 ) );
+		$term16 = $this->factory->tag->create( array( 'name' => 'A+' ) );
+		$this->assertTrue( is_wp_error( $term16 ) );
+		$term17 = $this->factory->tag->create( array( 'name' => 'A++' ) );
+		$this->assertFalse( is_wp_error( $term17 ) );
+		$term18 = $this->factory->tag->create( array( 'name' => 'A-', 'slug' => 'a' ) );
+		$this->assertFalse( is_wp_error( $term18 ) );
+		$term19 = $this->factory->tag->create( array( 'name' => 'A-' ) );
+		$this->assertTrue( is_wp_error( $term19 ) );
+		$term20 = $this->factory->tag->create( array( 'name' => 'A--' ) );
+		$this->assertFalse( is_wp_error( $term20 ) );
+	}
 }
