Index: src/wp-admin/includes/misc.php
===================================================================
--- src/wp-admin/includes/misc.php	(revision 42428)
+++ src/wp-admin/includes/misc.php	(working copy)
@@ -56,6 +56,43 @@
 }
 
 /**
+ * Split input lines into lines preceding, contained by and following BEGIN and
+ * END markers (in the .htaccess file).
+ *
+ * @param array $lines Input file lines without newline characters.
+ * @param string $marker
+ * @return array Preceding, existing and following lines as arrays.
+ */
+function split_by_markers( $lines, $marker ) {
+	$start_marker = "# BEGIN {$marker}";
+	$end_marker   = "# END {$marker}";
+
+	$pre_lines = $post_lines = $existing_lines = array();
+	$found_start_marker = $found_end_marker = false;
+
+	foreach ( $lines as $line ) {
+		if ( ! $found_start_marker && ( $line === $start_marker ) ) {
+			$found_start_marker = true;
+			continue;
+		}
+		if ( ! $found_end_marker && ( $line === $end_marker ) ) {
+			$found_end_marker = true;
+			continue;
+		}
+
+		if ( ! $found_start_marker ) {
+			$pre_lines[] = $line;
+		} elseif ( ! $found_end_marker ) {
+			$existing_lines[] = $line;
+		} else {
+			$post_lines[] = $line;
+		}
+	}
+
+	return array( $pre_lines, $existing_lines, $post_lines );
+}
+
+/**
  * Extracts strings from between the BEGIN and END markers in the .htaccess file.
  *
  * @since 1.5.0
@@ -62,7 +99,7 @@
  *
  * @param string $filename
  * @param string $marker
- * @return array An array of strings from a file (.htaccess ) from between BEGIN and END markers.
+ * @return array An array of strings from a file (.htaccess) from between BEGIN and END markers.
  */
 function extract_from_markers( $filename, $marker ) {
 	$result = array();
@@ -71,19 +108,11 @@
 		return $result;
 	}
 
-	$markerdata = explode( "\n", implode( '', file( $filename ) ) );
+	$markerdata = @file( $filename, FILE_IGNORE_NEW_LINES );
 
-	$state = false;
-	foreach ( $markerdata as $markerline ) {
-		if ( false !== strpos( $markerline, '# END ' . $marker ) ) {
-			$state = false;
-		}
-		if ( $state ) {
-			$result[] = $markerline;
-		}
-		if ( false !== strpos( $markerline, '# BEGIN ' . $marker ) ) {
-			$state = true;
-		}
+	if ( ! empty( $markerdata ) ) {
+		// We are only interested in lines contained by marker.
+		list( , $result, ) = split_by_markers( $markerdata, $marker );
 	}
 
 	return $result;
@@ -90,7 +119,7 @@
 }
 
 /**
- * Inserts an array of strings into a file (.htaccess ), placing it between
+ * Inserts an array of strings into a file (.htaccess), placing it between
  * BEGIN and END markers.
  *
  * Replaces existing marked info. Retains surrounding
@@ -119,9 +148,6 @@
 		$insertion = explode( "\n", $insertion );
 	}
 
-	$start_marker = "# BEGIN {$marker}";
-	$end_marker   = "# END {$marker}";
-
 	$fp = fopen( $filename, 'r+' );
 	if ( ! $fp ) {
 		return false;
@@ -136,24 +162,7 @@
 	}
 
 	// Split out the existing file into the preceding lines, and those that appear after the marker
-	$pre_lines    = $post_lines = $existing_lines = array();
-	$found_marker = $found_end_marker = false;
-	foreach ( $lines as $line ) {
-		if ( ! $found_marker && false !== strpos( $line, $start_marker ) ) {
-			$found_marker = true;
-			continue;
-		} elseif ( ! $found_end_marker && false !== strpos( $line, $end_marker ) ) {
-			$found_end_marker = true;
-			continue;
-		}
-		if ( ! $found_marker ) {
-			$pre_lines[] = $line;
-		} elseif ( $found_marker && $found_end_marker ) {
-			$post_lines[] = $line;
-		} else {
-			$existing_lines[] = $line;
-		}
-	}
+	list($pre_lines, $existing_lines, $post_lines) = split_by_markers($lines, $marker);
 
 	// Check to see if there was a change
 	if ( $existing_lines === $insertion ) {
@@ -167,9 +176,9 @@
 	$new_file_data = implode(
 		"\n", array_merge(
 			$pre_lines,
-			array( $start_marker ),
+			array( "# BEGIN {$marker}" ),
 			$insertion,
-			array( $end_marker ),
+			array( "# END {$marker}" ),
 			$post_lines
 		)
 	);
