From 48035be648115a3b7f0ed0563a8d7c0c5fb0529e Mon Sep 17 00:00:00 2001 From: Hamza Ali Date: Sat, 17 Aug 2024 22:54:20 +0500 Subject: [PATCH] Fix Marshalls `raw/utf8_to_base64` from erroring on empty input. As per RFC 4648 (https://www.rfc-editor.org/rfc/rfc4648#section-10), the base64 encoding for an empty ("") input is also empty. The functionality in the Marshalls package coincedentially returns the correct result, but produces an error as well. The `variant_to_base64` function remains unchanged since an encoded variant cannot be empty. --- core/core_bind.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/core/core_bind.cpp b/core/core_bind.cpp index a15085bcde5..168d5c0e56c 100644 --- a/core/core_bind.cpp +++ b/core/core_bind.cpp @@ -1142,6 +1142,9 @@ Variant Marshalls::base64_to_variant(const String &p_str, bool p_allow_objects) } String Marshalls::raw_to_base64(const Vector &p_arr) { + if (p_arr.is_empty()) { + return ""; + } String ret = CryptoCore::b64_encode_str(p_arr.ptr(), p_arr.size()); ERR_FAIL_COND_V(ret.is_empty(), ret); return ret; @@ -1165,6 +1168,9 @@ Vector Marshalls::base64_to_raw(const String &p_str) { } String Marshalls::utf8_to_base64(const String &p_str) { + if (p_str.is_empty()) { + return ""; + } CharString cstr = p_str.utf8(); String ret = CryptoCore::b64_encode_str((unsigned char *)cstr.get_data(), cstr.length()); ERR_FAIL_COND_V(ret.is_empty(), ret);