mirror of
				https://github.com/Jermolene/TiddlyWiki5
				synced 2025-10-31 15:42:59 +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:
		| @@ -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: ""}) | ||||
| 	}); | ||||
| }; | ||||
|   | ||||
| @@ -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> | ||||
		Reference in New Issue
	
	Block a user
	 btheado
					btheado