mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-11-26 03:27:18 +00:00
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:
parent
a7bafd8840
commit
8e9d8d4fef
@ -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);
|
output = $tw.utils.replaceString(output,new RegExp("\\$" + $tw.utils.escapeRegExp(substitute.name) + "\\$","mg"),substitute.value);
|
||||||
});
|
});
|
||||||
// Substitute any variable references with their values
|
// 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: ""})
|
return widget.getVariable(varname,{defaultValue: ""})
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
@ -6,14 +6,16 @@ tags: [[$:/tags/wiki-test-spec]]
|
|||||||
title: Output
|
title: Output
|
||||||
|
|
||||||
\whitespace trim
|
\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)$
|
<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>
|
</div>
|
||||||
</$let>
|
</$let>
|
||||||
|
</$set>
|
||||||
|
|
||||||
+
|
+
|
||||||
title: ExpectedResult
|
title: ExpectedResult
|
||||||
|
|
||||||
<p><div attrib="myvalue" blankattrib="" class="TiddlyWiki
|
<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>
|
Loading…
Reference in New Issue
Block a user