summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2005-08-07 06:19:17 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 13:31:28 -0500
commit0c15c024118debc4e87908ed8d23c314f38f28ed (patch)
tree3af7946218b18307b46644fd9c47f80d13578d85
parentf13fbd7e6fcdf8fe6de2d9be2fd453fe22fc5e16 (diff)
downloadsamba-0c15c024118debc4e87908ed8d23c314f38f28ed.tar.gz
samba-0c15c024118debc4e87908ed8d23c314f38f28ed.tar.bz2
samba-0c15c024118debc4e87908ed8d23c314f38f28ed.zip
r9174: ejs does not include the special variable 'length' in for loops over objects,
so we need to check for it separately in the object lineariser (This used to be commit ea3c3d0a0f79c49c2e93da4956cc509614f92f37)
-rw-r--r--source4/scripting/libjs/encoder.js50
1 files changed, 32 insertions, 18 deletions
diff --git a/source4/scripting/libjs/encoder.js b/source4/scripting/libjs/encoder.js
index 65b2854d30..24508f3f6b 100644
--- a/source4/scripting/libjs/encoder.js
+++ b/source4/scripting/libjs/encoder.js
@@ -21,6 +21,9 @@ function __count_members(o) {
for (i in o) {
count++;
}
+ if (o.length != undefined) {
+ count++;
+ }
return count;
}
@@ -31,28 +34,39 @@ function __replace(str, old, rep) {
return s.join(rep, a);
}
+function encodeElement(e, name) {
+ var t = typeof(e);
+ var r;
+ var s = string_init();
+ if (t == 'object' && e == null) {
+ t = 'null';
+ }
+ if (t == 'object') {
+ r = s.sprintf("%s:%s:%s", name, t, encodeObject(e));
+ } else if (t == "string") {
+ var enc = s.encodeURIComponent(e);
+ var rep = __replace(enc, '%', '#');
+ r = s.sprintf("%s:%s:%s:",
+ name, t, __replace(s.encodeURIComponent(e),'%','#'));
+ } else if (t == "boolean" || t == "number") {
+ r = s.sprintf("%s:%s:%s:", name, t, "" + e);
+ } else if (t == "undefined" || t == "null") {
+ r = s.sprintf("%s:%s:", name, t);
+ } else {
+ println("Unable to linearise type " + t);
+ r = "";
+ }
+ return r;
+}
+
function encodeObject(o) {
var s = string_init();
var i, r = s.sprintf("%u:", __count_members(o));
for (i in o) {
- var t = typeof(o[i]);
- if (t == 'object' && o[i] == null) {
- t = 'null';
- }
- if (t == 'object') {
- r = s.sprintf("%s%s:%s:%s", r, i, t, encodeObject(o[i]));
- } else if (t == "string") {
- var enc = s.encodeURIComponent(o[i]);
- var rep = __replace(enc, '%', '#');
- r = s.sprintf("%s%s:%s:%s:",
- r, i, t, __replace(s.encodeURIComponent(o[i]),'%','#'));
- } else if (t == "boolean" || t == "number") {
- r = s.sprintf("%s%s:%s:%s:", r, i, t, "" + o[i]);
- } else if (t == "undefined" || t == "null") {
- r = s.sprintf("%s%s:%s:", r, i, t);
- } else {
- println("Unable to linearise type " + t);
- }
+ r = r + encodeElement(o[i], i);
+ }
+ if (o.length != undefined) {
+ r = r + encodeElement(o.length, 'length');
}
return r;
}