diff --git a/projects/plugins/jetpack/changelog/fix-stats-explode-trailing-newline b/projects/plugins/jetpack/changelog/fix-stats-explode-trailing-newline new file mode 100644 index 0000000000000..591df46c8f0a5 --- /dev/null +++ b/projects/plugins/jetpack/changelog/fix-stats-explode-trailing-newline @@ -0,0 +1,5 @@ +Significance: patch +Type: other +Comment: Fix bug in #39665 related to a trailing newline in the CSV data. + + diff --git a/projects/plugins/jetpack/modules/stats.php b/projects/plugins/jetpack/modules/stats.php index e306bc9d180e9..cf12fe07c5ee9 100644 --- a/projects/plugins/jetpack/modules/stats.php +++ b/projects/plugins/jetpack/modules/stats.php @@ -1668,7 +1668,7 @@ function stats_get_remote_csv( $url ) { */ function stats_str_getcsv( $csv ) { // @todo Correctly handle embedded newlines. Note, despite claims online, `str_getcsv( $csv, "\n" )` does not actually work. - $lines = explode( "\n", $csv ); + $lines = explode( "\n", rtrim( $csv, "\n" ) ); return array_map( function ( $line ) { // @todo When we drop support for PHP <7.4, consider passing empty-string for `$escape` here for better spec compatibility.