diff --git a/source/data/extend.mjs b/source/data/extend.mjs index cd6ba1dc0e0186e5734470fe0150b6e7888eb24f..cb82538ccd8bc404600dda238cc9a7a9845150e6 100644 --- a/source/data/extend.mjs +++ b/source/data/extend.mjs @@ -53,7 +53,7 @@ function extend(...args) { for (const k in a) { const v = a?.[k]; - if (v === o?.[k]) { + if ((k in o) && v === o?.[k]) { continue; } diff --git a/source/text/formatter.mjs b/source/text/formatter.mjs index eb3f4e1be84674a437dbef72d740790216e9dcbf..70b53a3f168e6a18a45586ee2f314ff63f4c7bb0 100644 --- a/source/text/formatter.mjs +++ b/source/text/formatter.mjs @@ -276,7 +276,10 @@ function format(text) { * @private * @license AGPLv3 * @since 1.12.0 - * @param text + * + * @param {string} text + * @param {string} openMarker + * @param {string} closeMarker * @return {string} */ function tokenize(text, openMarker, closeMarker) { @@ -287,6 +290,7 @@ function tokenize(text, openMarker, closeMarker) { const callbacks = this[internalSymbol]["callbacks"]; while (true) { + const startIndex = text.indexOf(openMarker); // no marker if (startIndex === -1) { @@ -339,7 +343,7 @@ function tokenize(text, openMarker, closeMarker) { const t1 = key.split("|").shift().trim(); // pipe symbol const t2 = t1.split("::").shift().trim(); // key value delimiter const t3 = t2.split(".").shift().trim(); // path delimiter - const prefix = this[workingDataSymbol]?.[t3] ? "path:" : "static:"; + const prefix = (t3 in this[workingDataSymbol]) ? "path:" : "static:"; let command = ""; if ( @@ -362,7 +366,6 @@ function tokenize(text, openMarker, closeMarker) { } formatted.push(validateString(pipe.run(this[workingDataSymbol]))); - text = text.substring(endIndex + closeMarker.length); } diff --git a/test/cases/text/formatter.mjs b/test/cases/text/formatter.mjs index 8a75f924c6e6e411ba3e7b10a43115902a3574a0..0341b67008b98dd76ac80a861bcdd6d4799e8afb 100644 --- a/test/cases/text/formatter.mjs +++ b/test/cases/text/formatter.mjs @@ -4,7 +4,27 @@ import {Formatter} from "../../../source/text/formatter.mjs"; describe('Formatter', function () { - // https://gitlab.schukai.com/oss/libraries/javascript/monster/-/issues/47 + // https://gitlab.schukai.com/oss/libraries/javascript/monster/-/issues/275 + describe('change empty handling', function () { + + it('modification 1', function () { + + const formatter = new Formatter({ + + a: null, + b: undefined, + c : 0 + + + }) + + expect(formatter.format("${a | tostring}")).to.be.equal('null'); + expect(formatter.format("${b | tostring}")).to.be.equal('undefined'); + expect(formatter.format("${c | tostring}")).to.be.equal('0'); + }) + }) + + // https://gitlab.schukai.com/oss/libraries/javascript/monster/-/issues/47 describe('examples', function () { it('rfc example should run', function () {