diff --git a/src/core/Ingredient.mjs b/src/core/Ingredient.mjs index d64bf763ba..319dfb158b 100755 --- a/src/core/Ingredient.mjs +++ b/src/core/Ingredient.mjs @@ -27,6 +27,7 @@ class Ingredient { this.toggleValues = []; this.target = null; this.defaultIndex = 0; + this.maxLength = null; this.min = null; this.max = null; this.step = 1; @@ -53,6 +54,7 @@ class Ingredient { this.toggleValues = ingredientConfig.toggleValues; this.target = typeof ingredientConfig.target !== "undefined" ? ingredientConfig.target : null; this.defaultIndex = typeof ingredientConfig.defaultIndex !== "undefined" ? ingredientConfig.defaultIndex : 0; + this.maxLength = ingredientConfig.maxLength || null; this.min = ingredientConfig.min; this.max = ingredientConfig.max; this.step = ingredientConfig.step; diff --git a/src/core/Operation.mjs b/src/core/Operation.mjs index 32ecff07ca..24739d3f78 100755 --- a/src/core/Operation.mjs +++ b/src/core/Operation.mjs @@ -184,6 +184,7 @@ class Operation { if (ing.disabled) conf.disabled = ing.disabled; if (ing.target) conf.target = ing.target; if (ing.defaultIndex) conf.defaultIndex = ing.defaultIndex; + if (ing.maxLength) conf.maxLength = ing.maxLength; if (typeof ing.min === "number") conf.min = ing.min; if (typeof ing.max === "number") conf.max = ing.max; if (ing.step) conf.step = ing.step; diff --git a/src/core/operations/FromBase85.mjs b/src/core/operations/FromBase85.mjs index aef1663892..d0c70da5a1 100644 --- a/src/core/operations/FromBase85.mjs +++ b/src/core/operations/FromBase85.mjs @@ -7,7 +7,7 @@ import Operation from "../Operation.mjs"; import OperationError from "../errors/OperationError.mjs"; import Utils from "../Utils.mjs"; -import {alphabetName, ALPHABET_OPTIONS} from "../lib/Base85.mjs"; +import {ALPHABET_OPTIONS} from "../lib/Base85.mjs"; /** * From Base85 operation @@ -40,8 +40,9 @@ class FromBase85 extends Operation { { name: "All-zero group char", type: "binaryShortString", - value: "z" - }, + value: "z", + maxLength: 1 + } ]; this.checks = [ { @@ -81,9 +82,8 @@ class FromBase85 extends Operation { */ run(input, args) { const alphabet = Utils.expandAlphRange(args[0]).join(""), - encoding = alphabetName(alphabet), removeNonAlphChars = args[1], - allZeroGroupChar = args[2], + allZeroGroupChar = typeof args[2] === "string" ? args[2].slice(0, 1) : "", result = []; if (alphabet.length !== 85 || @@ -91,6 +91,10 @@ class FromBase85 extends Operation { throw new OperationError("Alphabet must be of length 85"); } + if (allZeroGroupChar && alphabet.includes(allZeroGroupChar)) { + throw new OperationError("The all-zero group char cannot appear in the alphabet"); + } + // Remove delimiters if present const matches = input.match(/^<~(.+?)~>$/); if (matches !== null) input = matches[1]; @@ -109,7 +113,7 @@ class FromBase85 extends Operation { let i = 0; let block, blockBytes; while (i < input.length) { - if (encoding === "Standard" && input[i] === allZeroGroupChar) { + if (input[i] === allZeroGroupChar) { result.push(0, 0, 0, 0); i++; } else { diff --git a/src/web/HTMLIngredient.mjs b/src/web/HTMLIngredient.mjs index 2c638405c6..6d9ccdbfdf 100755 --- a/src/web/HTMLIngredient.mjs +++ b/src/web/HTMLIngredient.mjs @@ -30,6 +30,7 @@ class HTMLIngredient { this.rows = config.rows || false; this.target = config.target; this.defaultIndex = config.defaultIndex || 0; + this.maxLength = config.maxLength || null; this.toggleValues = config.toggleValues; this.ingId = this.app.nextIngId(); this.id = "ing-" + this.ingId; @@ -63,7 +64,8 @@ class HTMLIngredient { tabindex="${this.tabIndex}" arg-name="${this.name}" value="${this.value}" - ${this.disabled ? "disabled" : ""}> + ${this.disabled ? "disabled" : ""} + ${this.maxLength ? `maxlength="${this.maxLength}"` : ""}> `; break; case "shortString": @@ -78,7 +80,8 @@ class HTMLIngredient { tabindex="${this.tabIndex}" arg-name="${this.name}" value="${this.value}" - ${this.disabled ? "disabled" : ""}> + ${this.disabled ? "disabled" : ""} + ${this.maxLength ? `maxlength="${this.maxLength}"` : ""}> `; break; case "toggleString": @@ -93,7 +96,8 @@ class HTMLIngredient { tabindex="${this.tabIndex}" arg-name="${this.name}" value="${this.value}" - ${this.disabled ? "disabled" : ""}> + ${this.disabled ? "disabled" : ""} + ${this.maxLength ? `maxlength="${this.maxLength}"` : ""}>