From 284669544be3477106114617bc29b4d01a6f920c Mon Sep 17 00:00:00 2001 From: Saq Imtiaz Date: Mon, 17 Jul 2023 10:18:42 +0200 Subject: [PATCH] Trim whitespace when importing variables in $importvariables (#7611) * fix: trim whitespace when importing variables * feat: added tests for importing variables --- core/modules/widgets/importvariables.js | 2 +- .../data/importvariables/WithSetWidgets2.tid | 22 ++++++++++++++ .../WithSetWidgetsAndMacros.tid | 29 +++++++++++++++++++ 3 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 editions/test/tiddlers/tests/data/importvariables/WithSetWidgets2.tid create mode 100644 editions/test/tiddlers/tests/data/importvariables/WithSetWidgetsAndMacros.tid diff --git a/core/modules/widgets/importvariables.js b/core/modules/widgets/importvariables.js index aafc8ba8b..a8bb483b6 100644 --- a/core/modules/widgets/importvariables.js +++ b/core/modules/widgets/importvariables.js @@ -49,7 +49,7 @@ ImportVariablesWidget.prototype.execute = function(tiddlerList) { this.tiddlerList = tiddlerList || this.wiki.filterTiddlers(this.filter,this); // Accumulate the <$set> widgets from each tiddler $tw.utils.each(this.tiddlerList,function(title) { - var parser = widgetPointer.wiki.parseTiddler(title,{parseAsInline:true}); + var parser = widgetPointer.wiki.parseTiddler(title,{parseAsInline:true, configTrimWhiteSpace:true}); if(parser) { var parseTreeNode = parser.tree[0]; while(parseTreeNode && ["setvariable","set","parameters"].indexOf(parseTreeNode.type) !== -1) { diff --git a/editions/test/tiddlers/tests/data/importvariables/WithSetWidgets2.tid b/editions/test/tiddlers/tests/data/importvariables/WithSetWidgets2.tid new file mode 100644 index 000000000..23fa58c57 --- /dev/null +++ b/editions/test/tiddlers/tests/data/importvariables/WithSetWidgets2.tid @@ -0,0 +1,22 @@ +title: ImportVariables/WithSetWidgets2 +description: Import variables defined with a set widget without whitespace pragma +type: text/vnd.tiddlywiki-multiple +tags: [[$:/tags/wiki-test-spec]] + +title: Output + +\whitespace trim +\import Definitions +<$text text=<>/>, +<$text text=<>/> ++ +title: Definitions + +<$set name="one" value="elephant"> +<$set name="two" value="giraffe"> + + ++ +title: ExpectedResult + +

elephant,giraffe

\ No newline at end of file diff --git a/editions/test/tiddlers/tests/data/importvariables/WithSetWidgetsAndMacros.tid b/editions/test/tiddlers/tests/data/importvariables/WithSetWidgetsAndMacros.tid new file mode 100644 index 000000000..eaa81f38c --- /dev/null +++ b/editions/test/tiddlers/tests/data/importvariables/WithSetWidgetsAndMacros.tid @@ -0,0 +1,29 @@ +title: ImportVariables/WithSetWidgetsAndMacros +description: Import variables defined with a set widget without whitespace pragma +type: text/vnd.tiddlywiki-multiple +tags: [[$:/tags/wiki-test-spec]] + +title: Output + +\whitespace trim +\import Definitions +<$text text=<>/>, +<$text text=<
>/>, +<$text text=<>/>, +<$text text=<>/> ++ +title: Definitions + +\define name() Bugs Bunny +\procedure address() +Bunny Hill +\end + +<$set name="one" value="elephant"> +<$set name="two" value="giraffe"> + + ++ +title: ExpectedResult + +

Bugs Bunny,Bunny Hill,elephant,giraffe

\ No newline at end of file