From 2b817d953b312b58a43675aa8868851f2ca6bc40 Mon Sep 17 00:00:00 2001
From: Volker Schukai <volker.schukai@schukai.com>
Date: Fri, 3 Jan 2025 10:49:08 +0100
Subject: [PATCH] fix: update undefined handling #275

---
 source/data/extend.mjs        |  2 +-
 source/text/formatter.mjs     |  9 ++++++---
 test/cases/text/formatter.mjs | 22 +++++++++++++++++++++-
 3 files changed, 28 insertions(+), 5 deletions(-)

diff --git a/source/data/extend.mjs b/source/data/extend.mjs
index cd6ba1dc0..cb82538cc 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 eb3f4e1be..70b53a3f1 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 8a75f924c..0341b6700 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 () {
-- 
GitLab