From 7ad5f1bb14814bd05c6fe97e11b94c9f34936b15 Mon Sep 17 00:00:00 2001 From: Aaron Carlino Date: Tue, 17 Mar 2020 15:57:28 +1300 Subject: [PATCH] BUGFIX: Ensure diff arrays are one-dimensional --- src/View/Parsers/Diff.php | 1 + tests/php/View/Parsers/DiffTest.php | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/src/View/Parsers/Diff.php b/src/View/Parsers/Diff.php index 2072e854e..f1c314056 100644 --- a/src/View/Parsers/Diff.php +++ b/src/View/Parsers/Diff.php @@ -174,6 +174,7 @@ class Diff extends \Diff $content = $content ? "true" : "false"; } if (is_array($content)) { + $content = array_filter($content, 'is_scalar'); // Convert array to CSV $content = implode(',', $content); } diff --git a/tests/php/View/Parsers/DiffTest.php b/tests/php/View/Parsers/DiffTest.php index e778ffa84..9b5c45aa7 100644 --- a/tests/php/View/Parsers/DiffTest.php +++ b/tests/php/View/Parsers/DiffTest.php @@ -77,4 +77,15 @@ class DiffTest extends SapphireTest $this->assertRegExp($expected, $actual); } + + public function testDiffArray() + { + $from = ['Lorem', ['array here please ignore'], 'ipsum dolor']; + $to = 'Lorem,ipsum'; + $expected = "/^Lorem,ipsum *dolor<\/del> *$/"; + $actual = Diff::compareHTML($from, $to); + + $this->assertRegExp($expected, $actual); + + } }