Repository: godotengine/godot (language: cpp)

Issue:
Encoding empty string to base64 reports an error `Condition "ret.is_empty()" is true. Returning: ret`, but should not
### Tested versions

- Reproducible in v4.4.dev2.mono.official [97ef3c837] and v4.3.stable.mono.official [77dcf97d8]

### System information

Godot v4.4.dev2.mono - Windows 10.0.22631 - OpenGL 3 (Compatibility) - NVIDIA GeForce RTX 4070 Ti SUPER (NVIDIA; 32.0.15.6109) - AMD Ryzen 7 7800X3D 8-Core Processor (16 Threads)

### Issue description

When encoding the empty string as base64, the resulting base64 string is empty, as is appropriate per [RFC4648](https://www.rfc-editor.org/rfc/rfc4648#section-10). However, an error is reported: ```Condition "ret.is_empty()" is true. Returning: ret```. 

An error should not be reported, because an empty return value is appropriate in this case. 

Possible location of issue: https://github.com/godotengine/godot/blob/a0cd8f187a43935d756e49bf3778f39f0964f0ac/core/core_bind.cpp#L1234-L1238

### Steps to reproduce

1. Use the MRP below or add the following line to any method (such as a `_ready()` method)

```gdscript
	Marshalls.utf8_to_base64("")
```

2. Run the project.
3. Check the godot debugger > errors tab to see the incorrectly reported error.

### Minimal reproduction project (MRP)

[ret_project.zip](https://github.com/user-attachments/files/17825851/ret_project.zip)



Discussion / hints:
It seems like the easiest way to close this issue would be to just delete the error line, but I'm sure there's a reason that this exists? Maybe b64_encode_str returns an empty string if it fails? 

Maybe instead of deleting the line we could only report the error if the input string wasn't empty, or we could even check if the input trying is empty and if so just return an empty output string.

Fix patch:
diff --git a/core/core_bind.cpp b/core/core_bind.cpp
index cc7bb646d808..8b2de00c1938 100644
--- a/core/core_bind.cpp
+++ b/core/core_bind.cpp
@@ -1241,6 +1241,9 @@ Vector<uint8_t> Marshalls::base64_to_raw(const String &p_str) {
 }
 
 String Marshalls::utf8_to_base64(const String &p_str) {
+	if (p_str.is_empty()) {
+		return String();
+	}
 	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);


Test patch: