From 280701fbde340c15b6a081333984bf9e2fb684d9 Mon Sep 17 00:00:00 2001 From: Saq Imtiaz Date: Sat, 28 Mar 2026 13:04:29 +0100 Subject: [PATCH] Fixes MVV's so that getVariableInfo returns undefined (#9765) * wip: non-existent variables as attributes should be undefined * wip: non-existent variables as attributes should be undefined * tests: added missing test * fix: restore mistakenly commited files * fix: whitespace --- core/modules/widgets/action-log.js | 4 ++-- core/modules/widgets/widget.js | 4 ++-- .../transclude/MissingTiddlerAttributeVariable.tid | 13 +++++++++++++ 3 files changed, 17 insertions(+), 4 deletions(-) create mode 100644 editions/test/tiddlers/tests/data/transclude/MissingTiddlerAttributeVariable.tid diff --git a/core/modules/widgets/action-log.js b/core/modules/widgets/action-log.js index b9b9c52675..a8af05a493 100644 --- a/core/modules/widgets/action-log.js +++ b/core/modules/widgets/action-log.js @@ -61,7 +61,7 @@ LogWidget.prototype.log = function() { $tw.utils.each(this.parseTreeNode.attributes,function(attribute,name) { if(name.substring(0,2) !== "$$") { var resultList = self.computeAttribute(attribute,{asList: true}); - if(resultList.length <= 1) { + if(resultList && resultList.length <= 1) { data[name] = resultList[0] || ""; } else { data[name] = resultList; @@ -75,7 +75,7 @@ LogWidget.prototype.log = function() { allVars[v] = variable.value; } else { var variableInfo = this.getVariableInfo(v); - allVars[v] = variableInfo.resultList.length > 1 ? variableInfo.resultList : variableInfo.text; + allVars[v] = variableInfo && variableInfo.resultList && variableInfo.resultList.length > 1 ? variableInfo.resultList : variableInfo.text; } } if(this.filter) { diff --git a/core/modules/widgets/widget.js b/core/modules/widgets/widget.js index da25cf613e..e1dbb5296e 100755 --- a/core/modules/widgets/widget.js +++ b/core/modules/widgets/widget.js @@ -189,7 +189,7 @@ Widget.prototype.getVariableInfo = function(name,options) { } return { text: text, - resultList: [text] + resultList: text === undefined ? text : [text] }; }; @@ -338,7 +338,7 @@ Widget.prototype.makeFakeWidgetWithVariables = function(vars = {}) { const value = vars[name]; return Array.isArray(value) ? { text: value[0], resultList: value } - : { text: value, resultList: [value] }; + : { text: value, resultList: value === undefined ? value : [value] }; } opts = opts || {}; opts.variables = Object.assign({}, vars, opts.variables || {}); diff --git a/editions/test/tiddlers/tests/data/transclude/MissingTiddlerAttributeVariable.tid b/editions/test/tiddlers/tests/data/transclude/MissingTiddlerAttributeVariable.tid new file mode 100644 index 0000000000..eabd1a229c --- /dev/null +++ b/editions/test/tiddlers/tests/data/transclude/MissingTiddlerAttributeVariable.tid @@ -0,0 +1,13 @@ +title: Transclude/MissingTiddlerAttributeVariable +description: Missing Tiddler Attribute Variable +type: text/vnd.tiddlywiki-multiple +tags: [[$:/tags/wiki-test-spec]] + +title: Output +description: hello + +<$transclude tiddler=<> field="description"/> ++ +title: ExpectedResult + +

hello

\ No newline at end of file