Fix base32 unicode alphabet (#2380)

This commit is contained in:
loki1205
2026-07-03 11:39:33 +01:00
committed by GitHub
parent 740d350306
commit eccaf723f5
4 changed files with 110 additions and 4 deletions
+36
View File
@@ -65,6 +65,42 @@ TestRegister.addApiTests([
assert.strictEqual(result.toString(), "493e8136b759370a415ef2cf2f7a69690441ff86592aba082bc2e2e0");
}),
it("Composable Dish: toBase32 should support non-BMP Unicode alphabets", () => {
const alphabet = "🀇🀈🀉🀊🀋🀌🀍🀎🀏🀙🀚🀛🀜🀝🀞🀟🀠🀡🀐🀑🀒🀓🀔🀕🀖🀗🀘🀀🀁🀂🀃🀅";
const result = new Dish("hello")
.apply(toBase32, {alphabet})
.toString();
// Should not contain replacement characters
assert.equal(result.includes("�"), false);
// Should contain only symbols from the alphabet
for (const ch of Array.from(result)) {
assert.ok(Array.from(alphabet).includes(ch));
}
// "hello" => 8 Base32 symbols
assert.equal(Array.from(result).length, 8);
}),
it("Composable Dish: toBase32 should omit padding for 32-character Unicode alphabets", () => {
const alphabet = "🀇🀈🀉🀊🀋🀌🀍🀎🀏🀙🀚🀛🀜🀝🀞🀟🀠🀡🀐🀑🀒🀓🀔🀕🀖🀗🀘🀀🀁🀂🀃🀅";
const result = new Dish("hell")
.apply(toBase32, {alphabet})
.toString();
// Should not leak undefined from array indexing
assert.equal(result.includes("undefined"), false);
// Should not contain replacement characters
assert.equal(result.includes("�"), false);
// Unpadded Base32 output for 4-byte input should be 7 symbols
assert.equal(Array.from(result).length, 7);
}),
it("Dish translation: ArrayBuffer to ArrayBuffer", () => {
const dish = new Dish(new ArrayBuffer(10), 4);
dish.get("array buffer");
+32
View File
@@ -109,6 +109,38 @@ TestRegister.addApiTests([
assert.equal(3 + result, 35);
}),
it("toBase32: should support non-BMP Unicode alphabets", () => {
const alphabet = "🀇🀈🀉🀊🀋🀌🀍🀎🀏🀙🀚🀛🀜🀝🀞🀟🀠🀡🀐🀑🀒🀓🀔🀕🀖🀗🀘🀀🀁🀂🀃🀅";
const result = chef.toBase32("hello", {alphabet}).toString();
// Should not contain replacement characters
assert.equal(result.includes("�"), false);
// Should contain only symbols from the alphabet
for (const ch of Array.from(result)) {
assert.ok(Array.from(alphabet).includes(ch));
}
// "hello" => 8 Base32 symbols
assert.equal(Array.from(result).length, 8);
}),
it("toBase32: should omit padding for 32-character Unicode alphabets", () => {
const alphabet = "🀇🀈🀉🀊🀋🀌🀍🀎🀏🀙🀚🀛🀜🀝🀞🀟🀠🀡🀐🀑🀒🀓🀔🀕🀖🀗🀘🀀🀁🀂🀃🀅";
const result = chef.toBase32("hell", {alphabet}).toString();
// Should not leak undefined from array indexing
assert.equal(result.includes("undefined"), false);
// Should not contain replacement characters
assert.equal(result.includes("�"), false);
// Unpadded Base32 output for 4-byte input should be 7 symbols
assert.equal(Array.from(result).length, 7);
}),
it("chef.help: should exist", () => {
assert(chef.help);
}),