From 02695d5c2a5289aeb5c24d594204e877ce9c803e Mon Sep 17 00:00:00 2001 From: DigiLive Date: Wed, 5 Aug 2020 11:27:28 +0200 Subject: [PATCH 1/3] Fix #58 - Side by side diff shows empty diff --- lib/jblond/Diff/Renderer/Html/SideBySide.php | 29 +++++++++++++++++--- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/lib/jblond/Diff/Renderer/Html/SideBySide.php b/lib/jblond/Diff/Renderer/Html/SideBySide.php index 57c27be7..95b0c73f 100644 --- a/lib/jblond/Diff/Renderer/Html/SideBySide.php +++ b/lib/jblond/Diff/Renderer/Html/SideBySide.php @@ -208,15 +208,11 @@ public function generateLinesReplace(array $changes): string $fromLine = $changes['base']['offset'] + $lineNo + 1; $toLine = " "; $changedLine = " "; - if (isset($changes['changed']['lines'][$lineNo])) { $toLine = $changes['changed']['offset'] + $lineNo + 1; $changedLine = $changes['changed']['lines'][$lineNo]; } - $line = str_replace(["\0", "\1"], $this->options['deleteMarkers'], $line); - $changedLine = str_replace(["\0", "\1"], $this->options['insertMarkers'], $changedLine); - $html .= << $fromLine @@ -230,6 +226,31 @@ public function generateLinesReplace(array $changes): string HTML; } + + return $html; + } + + foreach ($changes['changed']['lines'] as $lineNo => $changedLine) { + $toLine = $changes['changed']['offset'] + $lineNo + 1; + $fromLine = " "; + $line = " "; + if (isset($changes['base']['lines'][$lineNo])) { + $fromLine = $changes['base']['offset'] + $lineNo + 1; + $line = $changes['base']['lines'][$lineNo]; + } + + $html .= << + $fromLine + + $line + + $toLine + + $changedLine + + +HTML; } return $html; From 369b1461d62b26268dbaeddeaf1919f5cab41738 Mon Sep 17 00:00:00 2001 From: DigiLive Date: Wed, 5 Aug 2020 12:21:18 +0200 Subject: [PATCH 2/3] Fix #58 - Side by side diff shows empty diff --- example/example.php | 4 ++-- lib/jblond/Diff/Renderer/Html/SideBySide.php | 6 ++++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/example/example.php b/example/example.php index caebc983..94985a3b 100644 --- a/example/example.php +++ b/example/example.php @@ -11,8 +11,8 @@ require '../vendor/autoload.php'; // Include two sample files for comparison. -$sampleA = file_get_contents(dirname(__FILE__) . '/a.txt'); -$sampleB = file_get_contents(dirname(__FILE__) . '/b.txt'); +$sampleA = file_get_contents(dirname(__FILE__) . '/c.txt'); +$sampleB = file_get_contents(dirname(__FILE__) . '/d.txt'); // Options for generating the diff. $customOptions = [ diff --git a/lib/jblond/Diff/Renderer/Html/SideBySide.php b/lib/jblond/Diff/Renderer/Html/SideBySide.php index 95b0c73f..992d029b 100644 --- a/lib/jblond/Diff/Renderer/Html/SideBySide.php +++ b/lib/jblond/Diff/Renderer/Html/SideBySide.php @@ -213,6 +213,9 @@ public function generateLinesReplace(array $changes): string $changedLine = $changes['changed']['lines'][$lineNo]; } + $line = str_replace(["\0", "\1"], $this->options['deleteMarkers'], $line); + $changedLine = str_replace(["\0", "\1"], $this->options['insertMarkers'], $changedLine); + $html .= << $fromLine @@ -239,6 +242,9 @@ public function generateLinesReplace(array $changes): string $line = $changes['base']['lines'][$lineNo]; } + $line = str_replace(["\0", "\1"], $this->options['deleteMarkers'], $line); + $changedLine = str_replace(["\0", "\1"], $this->options['insertMarkers'], $changedLine); + $html .= << $fromLine From 0946d5967ca435d81def7599061627761ce0357a Mon Sep 17 00:00:00 2001 From: DigiLive Date: Wed, 5 Aug 2020 16:16:39 +0200 Subject: [PATCH 3/3] Fix #58 - Side by side diff shows empty diff - Reverted used sample texts. --- example/example.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/example/example.php b/example/example.php index 94985a3b..caebc983 100644 --- a/example/example.php +++ b/example/example.php @@ -11,8 +11,8 @@ require '../vendor/autoload.php'; // Include two sample files for comparison. -$sampleA = file_get_contents(dirname(__FILE__) . '/c.txt'); -$sampleB = file_get_contents(dirname(__FILE__) . '/d.txt'); +$sampleA = file_get_contents(dirname(__FILE__) . '/a.txt'); +$sampleB = file_get_contents(dirname(__FILE__) . '/b.txt'); // Options for generating the diff. $customOptions = [