diff options
author | timonson <54777088+timonson@users.noreply.github.com> | 2020-10-13 03:12:10 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-10-13 12:12:10 +1100 |
commit | 1956cb81372b96bc476e74ab43a62a6e60861277 (patch) | |
tree | 014dd7c132239eab61cceb0d31b6d27304a8ead5 /std/encoding/base64url_test.ts | |
parent | 26639b3bac463768c65f7fc40a1c53317549e1eb (diff) |
fix(std/encoding): base64 properly encodes mbc and handles Uint8Arrays (#7807)
Fixes #6094
Fixes #4794
Diffstat (limited to 'std/encoding/base64url_test.ts')
-rw-r--r-- | std/encoding/base64url_test.ts | 25 |
1 files changed, 9 insertions, 16 deletions
diff --git a/std/encoding/base64url_test.ts b/std/encoding/base64url_test.ts index 59d67240f..99dcf260c 100644 --- a/std/encoding/base64url_test.ts +++ b/std/encoding/base64url_test.ts @@ -1,30 +1,24 @@ // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. + import { assertEquals } from "../testing/asserts.ts"; import { decode, encode } from "./base64url.ts"; const testsetString = [ ["", ""], + ["ß", "w58"], ["f", "Zg"], ["fo", "Zm8"], ["foo", "Zm9v"], ["foob", "Zm9vYg"], ["fooba", "Zm9vYmE"], ["foobar", "Zm9vYmFy"], - [">?>d?ß", "Pj8-ZD_f"], -]; - -const testsetBinary = [ - [new TextEncoder().encode("\x00"), "AA"], - [new TextEncoder().encode("\x00\x00"), "AAA"], - [new TextEncoder().encode("\x00\x00\x00"), "AAAA"], - [new TextEncoder().encode("\x00\x00\x00\x00"), "AAAAAA"], + [">?>d?ß", "Pj8-ZD_Dnw"], ]; -Deno.test("[encoding/base64url] testBase64urlEncodeString", () => { - for (const [input, output] of testsetString) { - assertEquals(encode(input), output); - } -}); +const testsetBinary = testsetString.map(([str, b64]) => [ + new TextEncoder().encode(str), + b64, +]) as Array<[Uint8Array, string]>; Deno.test("[encoding/base64url] testBase64urlEncodeBinary", () => { for (const [input, output] of testsetBinary) { @@ -32,9 +26,8 @@ Deno.test("[encoding/base64url] testBase64urlEncodeBinary", () => { } }); -Deno.test("[encoding/base64ur] testBase64urDecodeBinary", () => { +Deno.test("[decoding/base64url] testBase64urlDecodeBinary", () => { for (const [input, output] of testsetBinary) { - const outputBinary = new Uint8Array(decode(output as string)); - assertEquals(outputBinary, input as Uint8Array); + assertEquals(decode(output), input); } }); |