From 8840d1a61f3eacd0c41f802c3b4273f9d901a9a8 Mon Sep 17 00:00:00 2001 From: ewin Date: Thu, 27 Mar 2025 15:15:00 -0400 Subject: [PATCH] Use Unicode-tolerant base64 function --- src/util.mjs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/util.mjs b/src/util.mjs index 12bd843..60ac2b5 100644 --- a/src/util.mjs +++ b/src/util.mjs @@ -2,6 +2,15 @@ import {execSync} from 'node:child_process'; +/** + * Converts a string from UTF-8 to base64. + * @param {string} str + * @returns {string} + */ +function toBase64 (str) { + return Buffer.from(str, 'utf-8').toString('base64'); +} + /** * terrible terrible terrible string diff helper for debugging * @param {string} a @@ -12,9 +21,11 @@ export function diff (a, b) { // https://stackoverflow.com/a/60221847 // also use `|| true` to not throw an error when `diff` returns non-zero execSync(`bash -c ' - diff --color -u <(echo ${btoa(a)} | base64 -d) <(echo ${btoa(b)} | base64 -d) + diff --color -u <(echo ${toBase64(a)} | base64 -d) <(echo ${toBase64(b)} | base64 -d) ' || true`, { // display result directly in terminal stdio: 'inherit', }); } + +'yeet'