godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
91.48k stars 21.26k forks source link

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

Open brevven opened 1 week ago

brevven commented 1 week ago

Tested versions

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. 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)
    Marshalls.utf8_to_base64("")
  1. Run the project.
  2. Check the godot debugger > errors tab to see the incorrectly reported error.

Minimal reproduction project (MRP)

ret_project.zip

carsonetb commented 1 week ago

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.