Allow attribute substitution to handle variables containing non-word characters (#7606)

* Added failing test for #7604

* Fix attribute substitution regexp

Use the same regexp in wiki.getSubstitutedText as is used in
Widget.prototype.substituteVariableReferences. Fixes #7604.

* Added a test for a variable name containing spaces
This commit is contained in:
btheado 2023-07-14 15:42:31 -05:00 committed by GitHub
parent a7bafd8840
commit 8e9d8d4fef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 4 deletions

View File

@ -1086,7 +1086,7 @@ exports.getSubstitutedText = function(text,widget,options) {
output = $tw.utils.replaceString(output,new RegExp("\\$" + $tw.utils.escapeRegExp(substitute.name) + "\\$","mg"),substitute.value);
});
// Substitute any variable references with their values
return output.replace(/\$\((\w+)\)\$/g, function(match,varname) {
return output.replace(/\$\(([^\)\$]+)\)\$/g, function(match,varname) {
return widget.getVariable(varname,{defaultValue: ""})
});
};

View File

@ -6,14 +6,16 @@ tags: [[$:/tags/wiki-test-spec]]
title: Output
\whitespace trim
<$let project="TiddlyWiki" disabled="true">
<$set name="var with spaces" value="spaces">
<$let project="TiddlyWiki" disabled="true" var-with-dashes="dashes">
<div class=`$(project)$
${ [[Hello]addsuffix[There]] }$` attrib=`myvalue` otherattrib=`$(1)$` blankattrib=`` quoted="here" disabled=```$(disabled)$```>
${ [[Hello]addsuffix[There]] }$` attrib=`myvalue` otherattrib=`$(1)$` blankattrib=`` quoted="here" disabled=```$(disabled)$``` dashes=`$(var-with-dashes)$` spaces=`$(var with spaces)$`>
</div>
</$let>
</$set>
+
title: ExpectedResult
<p><div attrib="myvalue" blankattrib="" class="TiddlyWiki
HelloThere" disabled="true" otherattrib="" quoted="here"></div></p>
HelloThere" dashes="dashes" disabled="true" otherattrib="" quoted="here" spaces="spaces"></div></p>