diff --git a/src/exports/stash.js b/src/exports/stash.js index cd68a92..590c137 100644 --- a/src/exports/stash.js +++ b/src/exports/stash.js @@ -80,7 +80,6 @@ const stash = { getDataTemplate(path) { if (path) { - console.log(dataTemplate) return jq(path, { data: dataTemplate }).value; } return dataTemplate; diff --git a/src/helpers/dataProcessor.js b/src/helpers/dataProcessor.js index 5df6d27..8f72128 100644 --- a/src/helpers/dataProcessor.js +++ b/src/helpers/dataProcessor.js @@ -82,7 +82,14 @@ const dataProcessor = { } if (typeof data === 'object') { for (const prop in data) { - data[prop] = this.processDataRefs(data[prop]); + const updated_prop = this.getDataRefValue(prop); + if (typeof updated_prop === 'string' && updated_prop !== prop) { + data[updated_prop] = data[prop]; + delete data[prop]; + data[updated_prop] = this.processDataRefs(data[updated_prop]); + } else { + data[prop] = this.processDataRefs(data[prop]); + } } } return data; diff --git a/test/unit/dataProcessor.spec.js b/test/unit/dataProcessor.spec.js index 862a93a..ff887e5 100644 --- a/test/unit/dataProcessor.spec.js +++ b/test/unit/dataProcessor.spec.js @@ -398,7 +398,7 @@ describe('Data Processing - Templates - Direct Overrides', () => { }); expect(config.data.template.enabled).equals(true); expect(config.data.template.processed).equals(true); - }); + }); }); @@ -786,6 +786,26 @@ describe('Data Processing - Actual Data - Only Maps', () => { }); }); + it('processData - should replace object key with string', () => { + let data = { + '$M{User.Name}': 'Name' + }; + data = dp.processData(data); + expect(data).deep.equals({ + 'Snow': 'Name' + }); + }); + + it('processData - should not replace object key', () => { + let data = { + '$M{User}': 'Name' + }; + data = dp.processData(data); + expect(data).deep.equals({ + '$M{User}': 'Name' + }); + }); + after(() => { stash.clearDataMaps(); });