Restrict variable substitutions to macros defined with the define pragma

Fixes #3333
single-tiddler-mode
Jermolene 2018-06-15 08:31:02 +01:00
rodzic aba9c94f5a
commit 35cbb127a3
4 zmienionych plików z 13 dodań i 6 usunięć

Wyświetl plik

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

Wyświetl plik

@ -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];
}

Wyświetl plik

@ -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();
};

Wyświetl plik

@ -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