@@ -105,10 +105,12 @@ final class Differ
105105 // show how many neighbor lines
106106 // Differ::CONTEXT_ALL can be used to show the whole file
107107 'context ' => 3 ,
108- // ignore case difference
109- 'ignoreWhitespace ' => false ,
110108 // ignore whitespace difference
111109 'ignoreCase ' => false ,
110+ // ignore line ending difference
111+ 'ignoreLineEnding ' => false ,
112+ // ignore case difference
113+ 'ignoreWhitespace ' => false ,
112114 ];
113115
114116 /**
@@ -306,8 +308,14 @@ public function getGroupedOpcodes(): array
306308 return $ this ->groupedOpcodes ;
307309 }
308310
309- $ old = $ this ->old ;
310- $ new = $ this ->new ;
311+ if ($ this ->options ['ignoreLineEnding ' ]) {
312+ $ old = array_map ([$ this , 'removeLineEnding ' ], $ this ->old );
313+ $ new = array_map ([$ this , 'removeLineEnding ' ], $ this ->new );
314+ } else {
315+ $ old = $ this ->old ;
316+ $ new = $ this ->new ;
317+ }
318+
311319 $ this ->getGroupedOpcodesPre ($ old , $ new );
312320
313321 $ opcodes = $ this ->sequenceMatcher
@@ -333,8 +341,14 @@ public function getGroupedOpcodesGnu(): array
333341 return $ this ->groupedOpcodesGnu ;
334342 }
335343
336- $ old = $ this ->old ;
337- $ new = $ this ->new ;
344+ if ($ this ->options ['ignoreLineEnding ' ]) {
345+ $ old = array_map ([$ this , 'removeLineEnding ' ], $ this ->old );
346+ $ new = array_map ([$ this , 'removeLineEnding ' ], $ this ->new );
347+ } else {
348+ $ old = $ this ->old ;
349+ $ new = $ this ->new ;
350+ }
351+
338352 $ this ->getGroupedOpcodesGnuPre ($ old , $ new );
339353
340354 $ opcodes = $ this ->sequenceMatcher
@@ -458,6 +472,16 @@ private function getGroupedOpcodesGnuPost(array &$opcodes): void
458472 $ this ->getGroupedOpcodesPost ($ opcodes );
459473 }
460474
475+ /**
476+ * Remove line ending characters at the end of the string.
477+ *
478+ * @param string $str the string
479+ */
480+ private function removeLineEnding (string $ str ): string
481+ {
482+ return rtrim ($ str , "\r\n" );
483+ }
484+
461485 /**
462486 * Claim this class has settled down and we could calculate cached
463487 * properties by current properties.
0 commit comments