Index: wp-includes/comment.php
===================================================================
--- wp-includes/comment.php	(revision 31385)
+++ wp-includes/comment.php	(working copy)
@@ -2517,7 +2517,6 @@
 		$excerpt = apply_filters( 'the_excerpt', $post->post_excerpt );
 	}
 
-	$excerpt = str_replace(']]>', ']]&gt;', $excerpt);
 	$excerpt = wp_html_excerpt($excerpt, 252, '&#8230;');
 
 	/** This filter is documented in wp-includes/post-template.php */
Index: wp-includes/feed-atom.php
===================================================================
--- wp-includes/feed-atom.php	(revision 31385)
+++ wp-includes/feed-atom.php	(working copy)
@@ -67,9 +67,9 @@
 		<updated><?php echo get_post_modified_time('Y-m-d\TH:i:s\Z', true); ?></updated>
 		<published><?php echo get_post_time('Y-m-d\TH:i:s\Z', true); ?></published>
 		<?php the_category_rss('atom') ?>
-		<summary type="<?php html_type_rss(); ?>"><![CDATA[<?php the_excerpt_rss(); ?>]]></summary>
+		<summary type="<?php html_type_rss(); ?>"><?php echo _esc_xml_cdata( get_the_excerpt_rss() ); ?></summary>
 <?php if ( !get_option('rss_use_excerpt') ) : ?>
-		<content type="<?php html_type_rss(); ?>" xml:base="<?php the_permalink_rss() ?>"><![CDATA[<?php the_content_feed('atom') ?>]]></content>
+		<content type="<?php html_type_rss(); ?>" xml:base="<?php the_permalink_rss() ?>"><?php echo _esc_xml_cdata( get_the_content_feed( 'atom' ) ); ?></content>
 <?php endif; ?>
 	<?php atom_enclosure();
 	/**
Index: wp-includes/feed-rdf.php
===================================================================
--- wp-includes/feed-rdf.php	(revision 31385)
+++ wp-includes/feed-rdf.php	(working copy)
@@ -67,10 +67,10 @@
 	<dc:creator><![CDATA[<?php the_author() ?>]]></dc:creator>
 	<?php the_category_rss('rdf') ?>
 <?php if (get_option('rss_use_excerpt')) : ?>
-	<description><![CDATA[<?php the_excerpt_rss() ?>]]></description>
+	<description><?php echo _esc_xml_cdata( get_the_excerpt_rss() ); ?></description>
 <?php else : ?>
-	<description><![CDATA[<?php the_excerpt_rss() ?>]]></description>
-	<content:encoded><![CDATA[<?php the_content_feed('rdf') ?>]]></content:encoded>
+	<description><?php echo _esc_xml_cdata( get_the_excerpt_rss() ); ?></description>
+	<content:encoded><?php echo _esc_xml_cdata( get_the_content_feed( 'rdf' ) ); ?></content:encoded>
 <?php endif; ?>
 	<?php
 	/**
Index: wp-includes/feed-rss.php
===================================================================
--- wp-includes/feed-rss.php	(revision 31385)
+++ wp-includes/feed-rss.php	(working copy)
@@ -30,7 +30,7 @@
 <?php while (have_posts()) : the_post(); ?>
 	<item>
 		<title><?php the_title_rss() ?></title>
-		<description><![CDATA[<?php the_excerpt_rss() ?>]]></description>
+		<description><?php echo _esc_xml_cdata( get_the_excerpt_rss() ); ?></description>
 		<link><?php the_permalink_rss() ?></link>
 		<?php
 		/**
Index: wp-includes/feed-rss2.php
===================================================================
--- wp-includes/feed-rss2.php	(revision 31385)
+++ wp-includes/feed-rss2.php	(working copy)
@@ -90,14 +90,14 @@
 
 		<guid isPermaLink="false"><?php the_guid(); ?></guid>
 <?php if (get_option('rss_use_excerpt')) : ?>
-		<description><![CDATA[<?php the_excerpt_rss(); ?>]]></description>
+		<description><?php echo _esc_xml_cdata( get_the_excerpt_rss() ); ?></description>
 <?php else : ?>
-		<description><![CDATA[<?php the_excerpt_rss(); ?>]]></description>
-	<?php $content = get_the_content_feed('rss2'); ?>
+		<description><?php echo _esc_xml_cdata( get_the_excerpt_rss() ); ?></description>
+	<?php $content = get_the_content_feed( 'rss2' ); ?>
 	<?php if ( strlen( $content ) > 0 ) : ?>
-		<content:encoded><![CDATA[<?php echo $content; ?>]]></content:encoded>
+		<content:encoded><?php echo _esc_xml_cdata( $content ); ?></content:encoded>
 	<?php else : ?>
-		<content:encoded><![CDATA[<?php the_excerpt_rss(); ?>]]></content:encoded>
+		<content:encoded><?php echo _esc_xml_cdata( get_the_excerpt_rss() ); ?></content:encoded>
 	<?php endif; ?>
 <?php endif; ?>
 		<wfw:commentRss><?php echo esc_url( get_post_comments_feed_link(null, 'rss2') ); ?></wfw:commentRss>
Index: wp-includes/feed.php
===================================================================
--- wp-includes/feed.php	(revision 31385)
+++ wp-includes/feed.php	(working copy)
@@ -184,7 +184,6 @@
 
 	/** This filter is documented in wp-includes/post-template.php */
 	$content = apply_filters( 'the_content', get_the_content() );
-	$content = str_replace(']]>', ']]&gt;', $content);
 	/**
 	 * Filter the post content for use in feeds.
 	 *
@@ -209,11 +208,13 @@
 }
 
 /**
- * Display the post excerpt for the feed.
+ * Retrieve the post excerpt for the feed.
  *
- * @since 0.71
+ * @since x.x.x
+ *
+ * @return string Current post excerpt.
  */
-function the_excerpt_rss() {
+function get_the_excerpt_rss() {
 	$output = get_the_excerpt();
 	/**
 	 * Filter the post excerpt for a feed.
@@ -222,10 +223,19 @@
 	 *
 	 * @param string $output The current post excerpt.
 	 */
-	echo apply_filters( 'the_excerpt_rss', $output );
+	return apply_filters( 'the_excerpt_rss', $output );
 }
 
 /**
+ * Display the post excerpt for the feed.
+ *
+ * @since 0.71
+ */
+function the_excerpt_rss() {
+	echo get_the_excerpt_rss();
+}
+
+/**
  * Display the permalink to the post for use in feeds.
  *
  * @since 2.3.0
Index: wp-includes/formatting.php
===================================================================
--- wp-includes/formatting.php	(revision 31385)
+++ wp-includes/formatting.php	(working copy)
@@ -2550,7 +2550,6 @@
 
 		/** This filter is documented in wp-includes/post-template.php */
 		$text = apply_filters( 'the_content', $text );
-		$text = str_replace(']]>', ']]&gt;', $text);
 
 		/**
 		 * Filter the number of words in an excerpt.
@@ -4015,3 +4014,20 @@
 
 	return $spaces;
 }
+
+/**
+ * Wrap a string in CDATA tags for inclusion of non-XML content in XML.
+ *
+ * The only invalid string in CDATA is "]]>". Since adjacent CDATA sections
+ * are equivalent to the result of their concatenation, the preferred method
+ * of including "]]>" is to split it between two sections.
+ *
+ * @since x.x.x
+ *
+ * @param string $string A string which might contain non-XML content.
+ * @return string A CDATA block containing the supplied string.
+ */
+function _esc_xml_cdata( $string ) {
+	$string = str_replace( ']]>', ']]]]><![CDATA[>', $string );
+	return '<![CDATA[' . $string . ']]>';
+}
Index: wp-includes/post-template.php
===================================================================
--- wp-includes/post-template.php	(revision 31385)
+++ wp-includes/post-template.php	(working copy)
@@ -219,7 +219,6 @@
 	 * @param string $content Content of the current post.
 	 */
 	$content = apply_filters( 'the_content', $content );
-	$content = str_replace( ']]>', ']]&gt;', $content );
 	echo $content;
 }
 
