Skip to content
Snippets Groups Projects
Verified Commit 2b817d95 authored by Volker Schukai's avatar Volker Schukai :alien:
Browse files

fix: update undefined handling #275

parent 5f991d6f
No related branches found
No related tags found
No related merge requests found
...@@ -53,7 +53,7 @@ function extend(...args) { ...@@ -53,7 +53,7 @@ function extend(...args) {
for (const k in a) { for (const k in a) {
const v = a?.[k]; const v = a?.[k];
if (v === o?.[k]) { if ((k in o) && v === o?.[k]) {
continue; continue;
} }
......
...@@ -276,7 +276,10 @@ function format(text) { ...@@ -276,7 +276,10 @@ function format(text) {
* @private * @private
* @license AGPLv3 * @license AGPLv3
* @since 1.12.0 * @since 1.12.0
* @param text *
* @param {string} text
* @param {string} openMarker
* @param {string} closeMarker
* @return {string} * @return {string}
*/ */
function tokenize(text, openMarker, closeMarker) { function tokenize(text, openMarker, closeMarker) {
...@@ -287,6 +290,7 @@ function tokenize(text, openMarker, closeMarker) { ...@@ -287,6 +290,7 @@ function tokenize(text, openMarker, closeMarker) {
const callbacks = this[internalSymbol]["callbacks"]; const callbacks = this[internalSymbol]["callbacks"];
while (true) { while (true) {
const startIndex = text.indexOf(openMarker); const startIndex = text.indexOf(openMarker);
// no marker // no marker
if (startIndex === -1) { if (startIndex === -1) {
...@@ -339,7 +343,7 @@ function tokenize(text, openMarker, closeMarker) { ...@@ -339,7 +343,7 @@ function tokenize(text, openMarker, closeMarker) {
const t1 = key.split("|").shift().trim(); // pipe symbol const t1 = key.split("|").shift().trim(); // pipe symbol
const t2 = t1.split("::").shift().trim(); // key value delimiter const t2 = t1.split("::").shift().trim(); // key value delimiter
const t3 = t2.split(".").shift().trim(); // path 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 = ""; let command = "";
if ( if (
...@@ -362,7 +366,6 @@ function tokenize(text, openMarker, closeMarker) { ...@@ -362,7 +366,6 @@ function tokenize(text, openMarker, closeMarker) {
} }
formatted.push(validateString(pipe.run(this[workingDataSymbol]))); formatted.push(validateString(pipe.run(this[workingDataSymbol])));
text = text.substring(endIndex + closeMarker.length); text = text.substring(endIndex + closeMarker.length);
} }
......
...@@ -4,7 +4,27 @@ import {Formatter} from "../../../source/text/formatter.mjs"; ...@@ -4,7 +4,27 @@ import {Formatter} from "../../../source/text/formatter.mjs";
describe('Formatter', function () { 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 () { describe('examples', function () {
it('rfc example should run', function () { it('rfc example should run', function () {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment