@@ -111,10 +111,12 @@ final class Differ
111111 // show how many neighbor lines
112112 // Differ::CONTEXT_ALL can be used to show the whole file
113113 'context ' => 3 ,
114- // ignore case difference
115- 'ignoreWhitespace ' => false ,
116114 // ignore whitespace difference
117115 'ignoreCase ' => false ,
116+ // ignore line ending difference
117+ 'ignoreLineEnding ' => false ,
118+ // ignore case difference
119+ 'ignoreWhitespace ' => false ,
118120 ];
119121
120122 /**
@@ -312,8 +314,14 @@ public function getGroupedOpcodes(): array
312314 return $ this ->groupedOpcodes ;
313315 }
314316
315- $ old = $ this ->old ;
316- $ new = $ this ->new ;
317+ if ($ this ->options ['ignoreLineEnding ' ]) {
318+ $ old = array_map ([$ this , 'removeLineEnding ' ], $ this ->old );
319+ $ new = array_map ([$ this , 'removeLineEnding ' ], $ this ->new );
320+ } else {
321+ $ old = $ this ->old ;
322+ $ new = $ this ->new ;
323+ }
324+
317325 $ this ->getGroupedOpcodesPre ($ old , $ new );
318326
319327 $ opcodes = $ this ->sequenceMatcher
@@ -338,8 +346,14 @@ public function getGroupedOpcodesGnu(): array
338346 return $ this ->groupedOpcodesGnu ;
339347 }
340348
341- $ old = $ this ->old ;
342- $ new = $ this ->new ;
349+ if ($ this ->options ['ignoreLineEnding ' ]) {
350+ $ old = array_map ([$ this , 'removeLineEnding ' ], $ this ->old );
351+ $ new = array_map ([$ this , 'removeLineEnding ' ], $ this ->new );
352+ } else {
353+ $ old = $ this ->old ;
354+ $ new = $ this ->new ;
355+ }
356+
343357 $ this ->getGroupedOpcodesGnuPre ($ old , $ new );
344358
345359 $ opcodes = $ this ->sequenceMatcher
@@ -462,6 +476,16 @@ private function getGroupedOpcodesGnuPost(array &$opcodes): void
462476 $ this ->getGroupedOpcodesPost ($ opcodes );
463477 }
464478
479+ /**
480+ * Remove line ending characters at the end of the string.
481+ *
482+ * @param string $str the string
483+ */
484+ private function removeLineEnding (string $ str ): string
485+ {
486+ return rtrim ($ str , "\r\n" );
487+ }
488+
465489 /**
466490 * Claim this class has settled down and we could calculate cached
467491 * properties by current properties.
0 commit comments