From d03ec295ed4d0ecb262291957c3d85a6b74bb747 Mon Sep 17 00:00:00 2001 From: Daniel Kesselberg Date: Thu, 12 Sep 2024 21:57:14 +0200 Subject: [PATCH] feat: add sieve utils Signed-off-by: Daniel Kesselberg --- lib/Sieve/SieveUtils.php | 38 +++++++++++++++++++++ tests/Unit/Sieve/SieveUtilsTest.php | 51 +++++++++++++++++++++++++++++ 2 files changed, 89 insertions(+) create mode 100644 lib/Sieve/SieveUtils.php create mode 100644 tests/Unit/Sieve/SieveUtilsTest.php diff --git a/lib/Sieve/SieveUtils.php b/lib/Sieve/SieveUtils.php new file mode 100644 index 0000000000..a6e9b5c652 --- /dev/null +++ b/lib/Sieve/SieveUtils.php @@ -0,0 +1,38 @@ +assertSame($expected, $actual); + } + + public static function providerEscapeString(): array { + return [ + ['foo"bar', 'foo\"bar'], + ['foo\\bar', 'foo\\\\bar'], + ['foo"\\bar', 'foo\"\\\\bar'], + ['foobar', 'foobar'], + ['', ''], + ]; + } + + /** + * @dataProvider providerStringList + */ + public function testStringList(array $values, string $expected): void { + $actual = SieveUtils::stringList($values); + $this->assertSame($expected, $actual); + } + + public static function providerStringList(): array { + return [ + [['Hello', 'World'], '["Hello", "World"]'], + [['foo"bar', 'foo\\bar'], '["foo\"bar", "foo\\\\bar"]'], + [['foo"bar', 'foo\\bar', 'foo"\\bar'], '["foo\"bar", "foo\\\\bar", "foo\"\\\\bar"]'], + [['foobar'], '["foobar"]'], + [[], '[""]'], + ]; + } +}