@@ -338,5 +338,69 @@ public function test_import_from_file_with_windows_line_endings_should_work_as_w
338338 $ this ->assertCount ( 1 , $ po ->entries );
339339 }
340340
341+ /**
342+ * @ticket 64928
343+ *
344+ * @dataProvider data_import_from_file_with_various_line_endings
345+ */
346+ public function test_import_from_file_with_various_line_endings ( $ newline , $ printable_newline ) {
347+ $ import_file = $ this ->temp_filename ();
348+
349+ $ file = 'msgid "" ' . $ newline ;
350+ $ file .= 'msgstr "" ' . $ newline ;
351+ $ file .= '"Project-Id-Version: WordPress 7.0\n" ' . $ newline ;
352+ $ file .= '"Plural-Forms: nplurals=2; plural=n != 1;\n" ' ;
353+
354+ $ entries = array ();
355+ for ( $ i = 1 ; $ i <= 3 ; $ i ++ ) {
356+ $ file .= $ newline ;
357+ $ file .= $ newline ;
358+ $ line = "Entry $ i " ;
359+ $ file .= 'msgid " ' . $ line . '" ' . $ newline ;
360+ $ file .= 'msgstr "" ' ;
361+ $ entry = new Translation_Entry ( array ( 'singular ' => $ line ) );
362+
363+ $ entries [ $ entry ->key () ] = $ entry ;
364+ }
365+
366+ file_put_contents ( $ import_file , $ file );
367+
368+ $ po = new PO ();
369+ $ res = $ po ->import_from_file ( $ import_file );
370+ unlink ( $ import_file );
371+
372+ $ this ->assertTrue ( $ res );
373+
374+ $ this ->assertSame (
375+ array (
376+ 'Project-Id-Version ' => 'WordPress 7.0 ' ,
377+ 'Plural-Forms ' => 'nplurals=2; plural=n != 1; ' ,
378+ ),
379+ $ po ->headers
380+ );
381+
382+ $ this ->assertEquals ( $ po ->entries , $ entries , 'Failed for ' . $ printable_newline );
383+
384+ $ export_file = $ this ->temp_filename ();
385+ $ po ->export_to_file ( $ export_file );
386+ $ content = file_get_contents ( $ export_file );
387+ unlink ( $ export_file );
388+
389+ $ this ->assertSame ( str_replace ( $ newline , "\n" , $ file ), $ content );
390+ }
391+
392+ /**
393+ * Data provider.
394+ *
395+ * @return array[]
396+ */
397+ public static function data_import_from_file_with_various_line_endings () {
398+ return array (
399+ '\r ' => array ( "\r" , '\r ' ),
400+ '\n ' => array ( "\n" , '\n ' ),
401+ '\r\n ' => array ( "\r\n" , '\r\n ' ),
402+ );
403+ }
404+
341405 // TODO: Add tests for bad files.
342406}
0 commit comments