Index: feed.php
===================================================================
--- feed.php	(revision 11981)
+++ feed.php	(working copy)
@@ -290,29 +290,34 @@
 	$categories = get_the_category();
 	$tags = get_the_tags();
 	$the_list = '';
-	$cat_names = array();
+	$cats = array();
 
 	$filter = 'rss';
 	if ( 'atom' == $type )
 		$filter = 'raw';
 
-	if ( !empty($categories) ) foreach ( (array) $categories as $category ) {
-		$cat_names[] = sanitize_term_field('name', $category->name, $category->term_id, 'category', $filter);
+	if ( !empty($categories) ) foreach ( (array) $categories as $category ) {         
+		$cat_name = sanitize_term_field('name', $category->name, $category->term_id, 'category', $filter);
+		$cats[$cat_name] = $category;
 	}
 
 	if ( !empty($tags) ) foreach ( (array) $tags as $tag ) {
-		$cat_names[] = sanitize_term_field('name', $tag->name, $tag->term_id, 'post_tag', $filter);
+		$cat_name = sanitize_term_field('name', $tag->name, $tag->term_id, 'post_tag', $filter);
+		$cats[$cat_name] = $tag;
 	}
 
-	$cat_names = array_unique($cat_names);
-
-	foreach ( $cat_names as $cat_name ) {
-		if ( 'rdf' == $type )
+	foreach ( $cats as $cat_name => $category ) {
+		if ( 'rdf' == $type ) {
 			$the_list .= "\t\t<dc:subject><![CDATA[$cat_name]]></dc:subject>\n";
-		elseif ( 'atom' == $type )
-			$the_list .= sprintf( '<category scheme="%1$s" term="%2$s" />', esc_attr( apply_filters( 'get_bloginfo_rss', get_bloginfo( 'url' ) ) ), esc_attr( $cat_name ) );
-		else
-			$the_list .= "\t\t<category><![CDATA[" . @html_entity_decode( $cat_name, ENT_COMPAT, get_option('blog_charset') ) . "]]></category>\n";
+		} elseif ( 'atom' == $type ) {
+			$blog_url = apply_filters( 'get_bloginfo_rss', get_bloginfo( 'url' ) );
+			$scheme = attribute_escape( $category->taxonomy =='post_tag' ? $blog_url . "/tag/" : $blog_url . "/category/" ); 
+		 	$label = attribute_escape( $cat_name ); 
+		 	$the_list .= "\n\t\t<category scheme=\"$scheme\" term=\"{$category->slug}\" label=\"$label\"/>\n";
+		} else {
+			$domain = $category->taxonomy =='post_tag' ? "tag" : "category";
+			$the_list .= "\n\t\t<category domain=\"$domain\"><![CDATA[" . @html_entity_decode( $cat_name, ENT_COMPAT, get_option('blog_charset') ) . "]]></category>\n";
+		}
 	}
 
 	return apply_filters('the_category_rss', $the_list, $type);
