r17548: It is a good idea to commit the fix (from mkhl) before the test that
authorAndrew Bartlett <abartlet@samba.org>
Tue, 15 Aug 2006 02:39:38 +0000 (02:39 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 19:15:37 +0000 (14:15 -0500)
commit8a6908200b1e459bc9067a9d1f9635185a7eee16
treec12257f5540e411dd16ee6d06c4249fb30feaa8f
parentc2c72565e4efef44068c4f176619942f60a9cf6e
r17548: It is a good idea to commit the fix (from mkhl) before the test that
shows the need for...

Martin Kuhl writes:

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.
source/scripting/libjs/base.js