mirror of
https://github.com/lightpanda-io/browser.git
synced 2026-03-22 12:44:43 +00:00
window.atob must trim input
This commit is contained in:
@@ -52,6 +52,7 @@
|
|||||||
<script id=btoa>
|
<script id=btoa>
|
||||||
testing.expectEqual('SGVsbG8gV29ybGQh', btoa('Hello World!'));
|
testing.expectEqual('SGVsbG8gV29ybGQh', btoa('Hello World!'));
|
||||||
testing.expectEqual('', btoa(''));
|
testing.expectEqual('', btoa(''));
|
||||||
|
testing.expectEqual('IA==', btoa(' '));
|
||||||
testing.expectEqual('YQ==', btoa('a'));
|
testing.expectEqual('YQ==', btoa('a'));
|
||||||
testing.expectEqual('YWI=', btoa('ab'));
|
testing.expectEqual('YWI=', btoa('ab'));
|
||||||
testing.expectEqual('YWJj', btoa('abc'));
|
testing.expectEqual('YWJj', btoa('abc'));
|
||||||
@@ -62,6 +63,13 @@
|
|||||||
<script id=atob>
|
<script id=atob>
|
||||||
testing.expectEqual('Hello World!', atob('SGVsbG8gV29ybGQh'));
|
testing.expectEqual('Hello World!', atob('SGVsbG8gV29ybGQh'));
|
||||||
testing.expectEqual('', atob(''));
|
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('a', atob('YQ=='));
|
||||||
testing.expectEqual('ab', atob('YWI='));
|
testing.expectEqual('ab', atob('YWI='));
|
||||||
testing.expectEqual('abc', atob('YWJj'));
|
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 {
|
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);
|
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;
|
return decoded;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user