From 0c15c024118debc4e87908ed8d23c314f38f28ed Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sun, 7 Aug 2005 06:19:17 +0000 Subject: 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) --- source4/scripting/libjs/encoder.js | 50 ++++++++++++++++++++++++-------------- 1 file changed, 32 insertions(+), 18 deletions(-) (limited to 'source4') 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; } -- cgit