diff --git a/src/simd/base64.zig b/src/simd/base64.zig index 81feeb723..a0ba45ea9 100644 --- a/src/simd/base64.zig +++ b/src/simd/base64.zig @@ -53,9 +53,9 @@ fn decodeScalar( /// For non-SIMD enabled builds, we trim the padding from the end of the /// base64 input in order to get identical output with the SIMD version. fn scalarInput(input: []const u8) []const u8 { - var i: usize = 0; - while (input[input.len - i - 1] == '=') i += 1; - return input[0 .. input.len - i]; + var end = input.len; + while (end > 0 and input[end - 1] == '=') end -= 1; + return input[0..end]; } // base64.cpp @@ -75,6 +75,14 @@ test "base64 maxLen" { try testing.expectEqual(11, len); } +test "base64 empty input" { + const testing = std.testing; + var output: [0]u8 = .{}; + + try testing.expectEqual(0, maxLen("")); + try testing.expectEqualStrings("", try decode("", &output)); +} + test "base64 decode" { const testing = std.testing; const alloc = testing.allocator;