From 66cbc6908a4c0009a01670be78962f4eb3a76090 Mon Sep 17 00:00:00 2001 From: TheSavageTeddy <51810476+TheSavageTeddy@users.noreply.github.com> Date: Fri, 25 Nov 2022 10:36:08 +0800 Subject: [PATCH] Better delimeter parsing for From Base85 --- src/core/operations/FromBase85.mjs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/core/operations/FromBase85.mjs b/src/core/operations/FromBase85.mjs index f9b37c74..0ffae967 100644 --- a/src/core/operations/FromBase85.mjs +++ b/src/core/operations/FromBase85.mjs @@ -91,8 +91,11 @@ class FromBase85 extends Operation { // Remove non-alphabet characters if (removeNonAlphChars) { - const re = new RegExp("[^" + alphabet.replace(/[[\]\\\-^$]/g, "\\$&") + "]", "g"); + const re = new RegExp("[^" + "z~" +alphabet.replace(/[[\]\\\-^$]/g, "\\$&") + "]", "g"); input = input.replace(re, ""); + // Remove delimiters again if present (incase of non-alphabet characters in front/behind delimiters) + const matches = input.match(/^<~(.+?)~>$/); + if (matches !== null) input = matches[1]; } if (input.length === 0) return []; @@ -111,7 +114,11 @@ class FromBase85 extends Operation { .map((chr, idx) => { const digit = alphabet.indexOf(chr); if (digit < 0 || digit > 84) { - throw `Invalid character '${chr}' at index ${i + idx}`; + if (chr === "z"){ + // Pass (Ignore character) + }else{ + throw `Invalid character '${chr}' at index ${i + idx}`; + } } return digit; });