diff --git a/wp-includes/pomo/po.php b/wp-includes/pomo/po.php index de1bc92064..c43544e142 100644 --- a/wp-includes/pomo/po.php +++ b/wp-includes/pomo/po.php @@ -13,16 +13,6 @@ if ( ! defined( 'PO_MAX_LINE_LEN' ) ) { define( 'PO_MAX_LINE_LEN', 79 ); } -/* - * The `auto_detect_line_endings` setting has been deprecated in PHP 8.1, - * but will continue to work until PHP 9.0. - * For now, we're silencing the deprecation notice as there may still be - * translation files around which haven't been updated in a long time and - * which still use the old MacOS standalone `\r` as a line ending. - * This fix should be revisited when PHP 9.0 is in alpha/beta. - */ -@ini_set( 'auto_detect_line_endings', 1 ); // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged - /** * Routines for working with PO files */ @@ -475,8 +465,31 @@ if ( ! class_exists( 'PO', false ) ) : $use_last_line = true; return true; } - $line = $use_last_line ? $last_line : fgets( $f ); - $line = ( "\r\n" === substr( $line, -2 ) ) ? rtrim( $line, "\r\n" ) . "\n" : $line; + + if ( $use_last_line ) { + $line = $last_line; + } else { + $line = fgets( $f ); + if ( false === $line ) { + return $line; + } + + // Handle \r-only terminated lines after the deprecation of auto_detect_line_endings in PHP 8.1. + $r = strpos( $line, "\r" ); + if ( false !== $r ) { + if ( strlen( $line ) === $r + 1 + && "\r\n" === substr( $line, $r ) + ) { + $line = rtrim( $line, "\r\n" ) . "\n"; + } else { + // The lines are terminated by just \r, so we end the line there and rewind. + $rewind = strlen( $line ) - $r - 1; + $line = substr( $line, 0, $r ) . "\n"; + fseek( $f, - $rewind, SEEK_CUR ); + } + } + } + $last_line = $line; $use_last_line = false; return $line; diff --git a/wp-includes/version.php b/wp-includes/version.php index 0374aa68b6..9756b560ce 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '7.0-beta6-62092'; +$wp_version = '7.0-beta6-62093'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.