From 6ac6cf729329559fa80ece1c057cb56fac81ff30 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Helleu?= Date: Tue, 1 Jun 2021 20:27:50 +0200 Subject: [PATCH] tests: add test of base64 encode/decode with NUL char in string --- tests/unit/core/test-core-string.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/unit/core/test-core-string.cpp b/tests/unit/core/test-core-string.cpp index b1dddbb2c..9ba1714e1 100644 --- a/tests/unit/core/test-core-string.cpp +++ b/tests/unit/core/test-core-string.cpp @@ -1911,6 +1911,9 @@ TEST(CoreString, Base64) str)); STRCMP_EQUAL(str_base64[i][1], str); } + /* test with a \0 in string */ + LONGS_EQUAL(20, string_base64_encode ("This is\0a test.", 15, str)); + STRCMP_EQUAL("VGhpcyBpcwBhIHRlc3Qu", str); /* string_base64_decode */ LONGS_EQUAL(-1, string_base64_decode (NULL, NULL)); @@ -1923,6 +1926,10 @@ TEST(CoreString, Base64) LONGS_EQUAL(length, string_base64_decode (str_base64[i][1], str)); STRCMP_EQUAL(str_base64[i][0], str); } + /* test with a \0 in string */ + LONGS_EQUAL(15, string_base64_decode ("VGhpcyBpcwBhIHRlc3Qu", str)); + MEMCMP_EQUAL("This is\0a test.", str, 15); + /* invalid base64 string, missing two "=" at the end */ LONGS_EQUAL(4, string_base64_decode ("dGVzdA", str)); STRCMP_EQUAL("test", str);