diff --git a/wp-admin/edit-form-advanced.php b/wp-admin/edit-form-advanced.php index c7b2cfcd94..56ba5e5c65 100644 --- a/wp-admin/edit-form-advanced.php +++ b/wp-admin/edit-form-advanced.php @@ -45,7 +45,7 @@ if ( 0 == $post_ID ) { // Detect if there exists an autosave newer than the post and if that autosave is different than the post if ( $autosave && mysql2date( 'U', $autosave->post_modified_gmt ) > mysql2date( 'U', $post->post_modified_gmt ) ) { foreach ( _wp_post_revision_fields() as $autosave_field => $_autosave_field ) { - if ( wp_text_diff( $autosave->$autosave_field, $post->$autosave_field ) ) { + if ( normalize_whitespace( $autosave->$autosave_field ) != normalize_whitespace( $post->$autosave_field ) ) { $notice = sprintf( $notices[1], get_edit_post_link( $autosave->ID ) ); break; } diff --git a/wp-includes/formatting.php b/wp-includes/formatting.php index 5192d95b95..f0c8d7e1e6 100644 --- a/wp-includes/formatting.php +++ b/wp-includes/formatting.php @@ -2144,4 +2144,12 @@ function _links_add_target( $m, $target ) { return '<' . $tag . $link . ' target="' . $target . '">'; } +// normalize EOL characters and strip duplicate whitespace +function normalize_whitespace( $str ) { + $str = trim($str); + $str = str_replace("\r", "\n", $str); + $str = preg_replace( array( '/\n+/', '/[ \t]+/' ), array( "\n", ' ' ), $str ); + return $str; +} + ?> diff --git a/wp-includes/pluggable.php b/wp-includes/pluggable.php index 49d4124fa5..0e8febeff7 100644 --- a/wp-includes/pluggable.php +++ b/wp-includes/pluggable.php @@ -1663,13 +1663,8 @@ function wp_text_diff( $left_string, $right_string, $args = null ) { if ( !class_exists( 'WP_Text_Diff_Renderer_Table' ) ) require( ABSPATH . WPINC . '/wp-diff.php' ); - // Normalize whitespace - $left_string = trim($left_string); - $right_string = trim($right_string); - $left_string = str_replace("\r", "\n", $left_string); - $right_string = str_replace("\r", "\n", $right_string); - $left_string = preg_replace( array( '/\n+/', '/[ \t]+/' ), array( "\n", ' ' ), $left_string ); - $right_string = preg_replace( array( '/\n+/', '/[ \t]+/' ), array( "\n", ' ' ), $right_string ); + $left_string = normalize_whitespace($left_string); + $right_string = normalize_whitespace($right_string); $left_lines = split("\n", $left_string); $right_lines = split("\n", $right_string);