From 478e085304e71fad9fbcad46d107f73e8f2e3db9 Mon Sep 17 00:00:00 2001 From: Srinivas-Saravanan Date: Mon, 27 Jan 2025 10:59:58 +0530 Subject: [PATCH] FIX_EXCEL_SANTIZE_HELPER_IMPROVED --- tests/unit/ExcelSanitizeHelperTest.php | 67 ++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 tests/unit/ExcelSanitizeHelperTest.php diff --git a/tests/unit/ExcelSanitizeHelperTest.php b/tests/unit/ExcelSanitizeHelperTest.php new file mode 100644 index 00000000..f098ece7 --- /dev/null +++ b/tests/unit/ExcelSanitizeHelperTest.php @@ -0,0 +1,67 @@ + "HelloWorld", + "withNonPrintable" => "‌71030034240400000016", + "withWhitespace" => " Trim me ", + "nonStringValue" => 'Hello +World', + ]; + $expected = [ + "validString" => "HelloWorld", + "withNonPrintable" => "71030034240400000016", + "withWhitespace" => "Trim me", + "nonStringValue" => 'HelloWorld', + ]; + $result = ExcelSanitizeHelper::sanitizeArrayData($input); + // var_dump($input); + // var_dump($result); + $this->assertSame($expected, ExcelSanitizeHelper::sanitizeArrayData($input)); + + // Test with nested arrays + $input = [ + "nested" => [ + "validString" => "‌71030034240400000016", + "withNonPrintable" => "Nested\x01\x02String_x000A_", + ], + "withWhitespace" => " Outer whitespace ", + ];var_dump($input); + $expected = [ + "nested" => [ + "validString" => "71030034240400000016", + "withNonPrintable" => "NestedString", + ], + "withWhitespace" => "Outer whitespace", + ]; + $this->assertSame($expected, ExcelSanitizeHelper::sanitizeArrayData($input)); + + // Test with empty array + $this->assertSame([], ExcelSanitizeHelper::sanitizeArrayData([])); + + // Test with an array containing only non-string values + $input = [ + "integer" => 42, + "float" => 3.14, + "boolean" => true, + "null" => null, + ]; + $this->assertSame($input, ExcelSanitizeHelper::sanitizeArrayData($input)); + + // Test with invalid input to ensure graceful handling (edge case) + $input = ["invalid" => "\x00\x01\x7F_x000D_", "normal" => "Text"]; + $expected = ["invalid" => "", "normal" => "Text"]; + $this->assertSame($expected, ExcelSanitizeHelper::sanitizeArrayData($input)); + } +}