1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-12-28 02:50:27 +00:00

Restrict variable substitutions to macros defined with the define pragma

Fixes #3333
This commit is contained in:
Jermolene 2018-06-15 08:31:02 +01:00
parent aba9c94f5a
commit 35cbb127a3
4 changed files with 13 additions and 6 deletions

View File

@ -84,7 +84,8 @@ exports.parse = function() {
value: {type: "string", value: text}
},
children: [],
params: params
params: params,
isMacroDefinition: true
}];
};

View File

@ -63,7 +63,8 @@ ImportVariablesWidget.prototype.execute = function(tiddlerList) {
addWidgetNode({
type: "set",
attributes: parseTreeNode.attributes,
params: parseTreeNode.params
params: parseTreeNode.params,
isMacroDefinition: parseTreeNode.isMacroDefinition
});
parseTreeNode = parseTreeNode.children[0];
}

View File

@ -48,7 +48,7 @@ SetWidget.prototype.execute = function() {
this.setValue = this.getAttribute("value");
this.setEmptyValue = this.getAttribute("emptyValue");
// Set context variable
this.setVariable(this.setName,this.getValue(),this.parseTreeNode.params);
this.setVariable(this.setName,this.getValue(),this.parseTreeNode.params,!!this.parseTreeNode.isMacroDefinition);
// Construct the child widgets
this.makeChildWidgets();
};

View File

@ -71,9 +71,10 @@ Set the value of a context variable
name: name of the variable
value: value of the variable
params: array of {name:, default:} for each parameter
isMacroDefinition: true if the variable is set via a \define macro pragma (and hence should have variable substitution performed)
*/
Widget.prototype.setVariable = function(name,value,params) {
this.variables[name] = {value: value, params: params};
Widget.prototype.setVariable = function(name,value,params,isMacroDefinition) {
this.variables[name] = {value: value, params: params, isMacroDefinition: !!isMacroDefinition};
};
/*
@ -102,7 +103,11 @@ Widget.prototype.getVariableInfo = function(name,options) {
$tw.utils.each(params,function(param) {
value = $tw.utils.replaceString(value,new RegExp("\\$" + $tw.utils.escapeRegExp(param.name) + "\\$","mg"),param.value);
});
value = this.substituteVariableReferences(value);
// Only substitute variable references if this variable was defined with the \define pragma
if(value.slice(0,4) ==="{{$(") {debugger;}
if(variable.isMacroDefinition) {
value = this.substituteVariableReferences(value);
}
return {
text: value,
params: params