[Samba4] [Patch] `substitute_var' fails on strings ending with "}"

Martin Kühl mkhl at samba.org
Tue Aug 1 23:16:08 GMT 2006


The ejs function `substitute_var' returns `undefined' when the first
argument ends in a pattern that should be substituted.

For that reason, the second assertion fails in the following test-case:

,----
| libinclude("base.js");
|
| var obj = new Object();
| obj.FOO = "foo";
| obj.BAR = "bar";
| var str1 = "${FOO}:${BAR}";
| var str2 = "${FOO}:${BAR} "; // note the space after the brace
| var sub1 = substitute_var(str1, obj);
| var sub2 = substitute_var(str2, obj);
|
| assert(str1 + " " == str2);
| assert(sub1 + " " == sub2);
`----

The problem is that the function `split' returns a single-element
array in both cases:
a) the string to split doesn't contain the split pattern
b) the string ends with the split pattern

To work around this, the following patch tests this condition and
returns `undefined' only if the string to split (`list[i]') really
didn't contain a closing brace.

Cheers,
Martin

Index: scripting/libjs/base.js
===================================================================
--- scripting/libjs/base.js	(Revision 17133)
+++ scripting/libjs/base.js	(Arbeitskopie)
@@ -72,7 +72,7 @@
 	var i;
 	for (i=1;i<list.length;i++) {
 		var list2 = split("}", list[i], 1);
-		if (list2.length < 2) {
+		if ((list2.length < 2) && (list2[0] + "}" != list[i])) {
 			return undefined;
 		}
 		var key = list2[0];


More information about the samba-technical mailing list