From 74ff7967bb010c4b6ababe345256a05893767310 Mon Sep 17 00:00:00 2001 From: Bart Blast Date: Thu, 17 Oct 2024 15:48:16 +0200 Subject: [PATCH] Serialize JS booleans --- assets/js/serializer.mjs | 3 ++- test/javascript/serializer_test.mjs | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/assets/js/serializer.mjs b/assets/js/serializer.mjs index 53de70f4b..c4c932683 100644 --- a/assets/js/serializer.mjs +++ b/assets/js/serializer.mjs @@ -40,7 +40,8 @@ export default class Serializer { if ( !serialized.startsWith('"') && !serialized.startsWith("{") && - !serialized.startsWith("[") + !serialized.startsWith("[") && + !["true", "false"].includes(serialized) ) { // [version, data] return `[1,"${serialized}"]`; diff --git a/test/javascript/serializer_test.mjs b/test/javascript/serializer_test.mjs index 7e7b4d0ff..a78caa4d0 100644 --- a/test/javascript/serializer_test.mjs +++ b/test/javascript/serializer_test.mjs @@ -213,6 +213,22 @@ describe("Serializer", () => { assert.equal(serialize(term), expected); }); }); + + describe("boolean", () => { + it("top-level", () => { + const term = true; + const expected = "[1,true]"; + + assert.equal(serialize(term), expected); + }); + + it("nested", () => { + const term = {a: true, b: 2}; + const expected = '[1,{"a":true,"b":2}]'; + + assert.equal(serialize(term), expected); + }); + }); }); }); });