Fixes bug in correctly resolving functions in text substitutions (#9598)

* fix: correctly resolve functions in text substitutions

* docs: added changenote

* fix: remove commented code
This commit is contained in:
Saq Imtiaz
2026-02-04 11:12:16 +00:00
committed by GitHub
parent 526aaa3db8
commit f6fd5ff261
3 changed files with 53 additions and 3 deletions
+4 -3
View File
@@ -1122,15 +1122,16 @@ Parse a block of text of a specified MIME type
Options include:
substitutions: an optional array of substitutions
*/
exports.getSubstitutedText = function(text,widget,options) {
exports.getSubstitutedText = function(text,thisWidget,options) {
options = options || {};
text = text || "";
var self = this,
widgetClass = widget.widget,
substitutions = options.substitutions || [],
output;
// Evaluate embedded filters and substitute with first result
output = text.replace(/\$\{([\S\s]+?)\}\$/g, function(match,filter) {
return self.filterTiddlers(filter,widget)[0] || "";
return self.filterTiddlers(filter,thisWidget)[0] || "";
});
// Process any substitutions provided in options
$tw.utils.each(substitutions,function(substitute) {
@@ -1138,7 +1139,7 @@ exports.getSubstitutedText = function(text,widget,options) {
});
// Substitute any variable references with their values
return output.replace(/\$\((.+?)\)\$/g, function(match,varname) {
return widget.getVariable(varname,{defaultValue: ""});
return widgetClass.evaluateVariable(thisWidget,varname, {defaultValue: ""})[0];
});
};
@@ -0,0 +1,38 @@
title: Functions/FunctionResolutionInSubstitute
description: Functions should resolve correctly in the substitute operator
type: text/vnd.tiddlywiki-multiple
tags: [[$:/tags/wiki-test-spec]]
title: Output
\whitespace trim
\function getIndex() [<index>add[1]]
\procedure template-with-var() $(getIndex)$
\procedure template-with-filteredexpression() ${ [<getIndex>] }$
\function test-with-substitute-variable()
[[abc]split[]] :map[<template-with-var>substitute[]] :and[join[ / ]]
\end
\function test-with-substitute-filteredexpression()
[[abc]split[]] :map[<template-with-filteredexpression>substitute[]] :and[join[ / ]]
\end
\function test-with-function()
[[abc]split[]] :map[function[getIndex]substitute[]] :and[join[ / ]]
\end
<<test-with-substitute-variable>>|
<<test-with-substitute-filteredexpression>>|
<<test-with-function>>
+
title: ExpectedResult
<p>1 / 2 / 3|1 / 2 / 3|1 / 2 / 3</p>
@@ -0,0 +1,11 @@
change-category: filters
change-type: bugfix
created: 20260120145005984
description: Fixes a bug with the resolution of functions within the substitute operator, where the function did not have access to variables set in the filter run.
github-contributors: saqimtiaz
github-links: https://github.com/TiddlyWiki/TiddlyWiki5/pull/9598
modified: 20260120145321774
release: 5.4.0
tags:
title: $:/changenotes/5.4.0/#9598
type: text/vnd.tiddlywiki