Author: ptw
Date: 2007-06-25 14:55:17 -0700 (Mon, 25 Jun 2007)
New Revision: 5513
Modified:
openlaszlo/branches/legals/WEB-INF/lps/lfc/debugger/LzFormat.lzs
openlaszlo/branches/legals/test/smoke/debugger.lzl
Log:
Change 20070622-ptw-C by [EMAIL PROTECTED] on 2007-06-22 08:36:04 EDT
in /Users/ptw/OpenLaszlo/legals-1
for http://svn.openlaszlo.org/openlaszlo/branches/legals
Summary: Robustify Debug.format's 'write compatibility' mode
Bugs Fixed:
LPP-4141 'Debugger enabled when JavaRpc returns a String containing '%' causes
an error'
Technical Reviewer: ben (Message-Id: <[EMAIL PROTECTED]>)
QA Reviewer: frisco (pending)
Doc Reviewer: (pending)
Details:
LzFormat: Fix type-oh that caused warning to fail (as reported in
bug). Make 'write compatibility' detector smarter. Make dealing
with unknown or incomplete control strings smarter (just echo the
unknown control). Print excess args in compatibility mode.
debugger: Added some test cases to verify that compatibility mode
works with random '%' characters.
Tests:
Test case from bug added to debugger smoke check
Modified: openlaszlo/branches/legals/WEB-INF/lps/lfc/debugger/LzFormat.lzs
===================================================================
--- openlaszlo/branches/legals/WEB-INF/lps/lfc/debugger/LzFormat.lzs
2007-06-25 20:57:50 UTC (rev 5512)
+++ openlaszlo/branches/legals/WEB-INF/lps/lfc/debugger/LzFormat.lzs
2007-06-25 21:55:17 UTC (rev 5513)
@@ -235,37 +235,37 @@
*/
Debug.formatToString = function (control, args) {
var al = arguments.length;
- // 'write compatibility mode': control is not a string or multiple
- // arguments and control has no formatting directives
+ // 'write compatibility mode': control is not a string or # of
+ // arguments is incompatible with control directives.
if ((! (typeof control == 'string' || control instanceof String)) ||
- ((al > 1) && (control.indexOf('%') == -1))) {
+ ((al > 1) != (control.indexOf('%') >= 0))) {
// Process each value to individually so they can be
// 'presented' as objects if applicable
- var msg = new LzMessage;
+ var out = new LzMessage;
for (var i = 0; i < al; i++) {
var arg = arguments[i];
var sep = ((i == (al-1)) ? '\n' : ' ');
- msg.append(arg);
+ out.append(arg);
// separator is always pretty
- msg.appendInternal(sep);
+ out.appendInternal(sep);
}
- return msg;
+ return out;
}
// Normal mode
if (al < 1) { control = '' };
var ctrl = '' + control;
// skip control
- var arg = 1;
+ var argno = 1;
var arglist = arguments;
function getarg(i) {
if (i >= al) {
- this.warn("%#0.48w: insufficient arguments", control);
+ Debug.warn("%#0.48w: insufficient arguments", control);
+ return null;
}
return arglist[i];
}
- var limit = ctrl.length;
- var start = 0;
- var end = 0;
+ var base = 0, limit = ctrl.length;
+ var start = 0, end = 0;
var out = new LzMessage();
while (start < limit) {
end = ctrl.indexOf('%');
@@ -275,6 +275,7 @@
}
out.append(ctrl.substring(start, end));
// skip %
+ base = end;
start = end + 1;
end = end + 2;
var sign = '-';
@@ -310,16 +311,16 @@
}
break;
case '$':
- arg = length;
+ argno = length;
length = '';
break;
case '*':
if (precision !== null) {
- precision = getarg(arg);
- arg++;
+ precision = getarg(argno);
+ argno++;
} else {
- length = getarg(arg);
- arg++;
+ length = getarg(argno);
+ argno++;
}
break;
case '.': precision = ''; break;
@@ -329,7 +330,7 @@
break;
}
}
- var value = getarg(arg);
+ var value = getarg(argno);
// set decimals
var decimals = null;
var force = false;
@@ -391,7 +392,7 @@
case 'D': case 'U': case 'I': case 'O': case 'X': case 'F': case 'E':
case 'G':
value = Number(value);
out.append(this.pad(value, length, decimals, pad, sign, radix,
force).toUpperCase());
- arg++; // consume value
+ argno++; // consume value
break;
case 'c':
value = String.fromCharCode(value);
@@ -409,37 +410,42 @@
}
out.appendInternal(this.pad(str, length, decimals, pad, sign, radix,
force),
value);
- arg++; // consume value
+ argno++; // consume value
break;
case 'd': case 'u': case 'i': case 'o': case 'x': case 'f': case 'e':
case 'g':
value = Number(value);
out.append(this.pad(value, length, decimals, pad, sign, radix, force));
- arg++; // consume value
+ argno++; // consume value
break;
case 'w':
var width = decimals || this.printLength;
out.appendInternal(this.pad(this.__String(value, (! alternate), width),
length, null, pad, sign, radix, force),
value);
- arg++; // consume value
+ argno++; // consume value
break;
- case null:
- break;
case '%':
- out.append(directive);
+ out.append('%');
break;
default:
- // ignore unknown
- out.append('%' + directive);
+ // treat unknown directive as literal
+ out.append(ctrl.substring(base, start));
break;
}
ctrl = ctrl.substring(start, limit);
- limit = ctrl.length;
- start = 0;
- end = 0;
+ base = 0, limit = ctrl.length;
+ start = 0, end = 0;
}
- if (arg < al) {
+ if (argno < al) {
this.warn("%#0.48w: excess arguments", control);
+ // Output excess in 'write compatibility' mode
+ out.appendInternal(' ');
+ for (; argno < al; argno++) {
+ var arg = getarg(argno);
+ var sep = ((argno == (al-1)) ? '\n' : ' ');
+ out.append(arg);
+ out.appendInternal(sep);
+ }
}
return out;
Modified: openlaszlo/branches/legals/test/smoke/debugger.lzl
===================================================================
--- openlaszlo/branches/legals/test/smoke/debugger.lzl 2007-06-25 20:57:50 UTC
(rev 5512)
+++ openlaszlo/branches/legals/test/smoke/debugger.lzl 2007-06-25 21:55:17 UTC
(rev 5513)
@@ -196,6 +196,15 @@
// assertEquals('3.141592653589 ',
Debug.formatToString('%-30.14w', Math.PI));
assertEquals('3.141 ',
Debug.formatToString('%-30.5s', Math.PI));
// assertEquals('3.141 ',
Debug.formatToString('%-30.5w', Math.PI));
+ // 'write' compatibility mode tests
+ assertEquals('%\n', Debug.formatToString('%'));
+ Debug.info("Expect an excess arguments warning");
+ assertEquals('% %\n', Debug.formatToString('%', '%'));
+ assertEquals('1 2 3\n', Debug.formatToString(1, 2, 3));
+ Debug.info("Expect an excess arguments warning");
+ assertEquals('%1 %2 %3\n', Debug.formatToString('%1', '%2',
'%3'));
+ Debug.info("Expect an excess arguments warning");
+ assertEquals('1% 2% 3%\n', Debug.formatToString('1%', '2%',
'3%'));
]]>
</method>
</class>
_______________________________________________
Laszlo-checkins mailing list
[email protected]
http://www.openlaszlo.org/mailman/listinfo/laszlo-checkins