mirror of
https://github.com/lightpanda-io/browser.git
synced 2026-03-21 20:24:42 +00:00
Merge pull request #1509 from lightpanda-io/atob-trim
window.atob must trim input
This commit is contained in:
@@ -52,6 +52,7 @@
|
||||
<script id=btoa>
|
||||
testing.expectEqual('SGVsbG8gV29ybGQh', btoa('Hello World!'));
|
||||
testing.expectEqual('', btoa(''));
|
||||
testing.expectEqual('IA==', btoa(' '));
|
||||
testing.expectEqual('YQ==', btoa('a'));
|
||||
testing.expectEqual('YWI=', btoa('ab'));
|
||||
testing.expectEqual('YWJj', btoa('abc'));
|
||||
@@ -62,6 +63,13 @@
|
||||
<script id=atob>
|
||||
testing.expectEqual('Hello World!', atob('SGVsbG8gV29ybGQh'));
|
||||
testing.expectEqual('', atob(''));
|
||||
|
||||
// atob must trim input
|
||||
testing.expectEqual('', atob(' '));
|
||||
testing.expectEqual(' ', atob('IA=='));
|
||||
testing.expectEqual(' ', atob(' IA=='));
|
||||
testing.expectEqual(' ', atob('IA== '));
|
||||
|
||||
testing.expectEqual('a', atob('YQ=='));
|
||||
testing.expectEqual('ab', atob('YWI='));
|
||||
testing.expectEqual('abc', atob('YWJj'));
|
||||
|
||||
@@ -373,9 +373,10 @@ pub fn btoa(_: *const Window, input: []const u8, page: *Page) ![]const u8 {
|
||||
}
|
||||
|
||||
pub fn atob(_: *const Window, input: []const u8, page: *Page) ![]const u8 {
|
||||
const decoded_len = std.base64.standard.Decoder.calcSizeForSlice(input) catch return error.InvalidCharacterError;
|
||||
const trimmed = std.mem.trim(u8, input, &std.ascii.whitespace);
|
||||
const decoded_len = std.base64.standard.Decoder.calcSizeForSlice(trimmed) catch return error.InvalidCharacterError;
|
||||
const decoded = try page.call_arena.alloc(u8, decoded_len);
|
||||
std.base64.standard.Decoder.decode(decoded, input) catch return error.InvalidCharacterError;
|
||||
std.base64.standard.Decoder.decode(decoded, trimmed) catch return error.InvalidCharacterError;
|
||||
return decoded;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user