From 0bdc147fa8706b5cc79415e4243b23b64b81e72e Mon Sep 17 00:00:00 2001 From: "igor%mir2.org" Date: Thu, 12 Feb 2004 19:05:47 +0000 Subject: [PATCH] Fixing NativeGlobal.encode: it was broken for chars beyond 0xFFFF as it sb.setLength(k) was called after k was increased to consume the second char from UTF-16 encoding to build UCS-4. --- .../src/org/mozilla/javascript/NativeGlobal.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/js/rhino/src/org/mozilla/javascript/NativeGlobal.java b/js/rhino/src/org/mozilla/javascript/NativeGlobal.java index d2c3bfc2ea2..ab70a0dc73d 100644 --- a/js/rhino/src/org/mozilla/javascript/NativeGlobal.java +++ b/js/rhino/src/org/mozilla/javascript/NativeGlobal.java @@ -535,6 +535,12 @@ public class NativeGlobal implements Serializable, IdFunctionMaster sb.append(C); } } else { + if (sb == null) { + sb = new StringBuffer(length + 3); + sb.append(str); + sb.setLength(k); + utf8buf = new byte[6]; + } if (0xDC00 <= C && C <= 0xDFFF) { throw cx.reportRuntimeError0("msg.bad.uri"); } @@ -552,12 +558,6 @@ public class NativeGlobal implements Serializable, IdFunctionMaster } V = ((C - 0xD800) << 10) + (C2 - 0xDC00) + 0x10000; } - if (utf8buf == null) { - utf8buf = new byte[6]; - sb = new StringBuffer(length + 3); - sb.append(str); - sb.setLength(k); - } int L = oneUcs4ToUtf8Char(utf8buf, V); for (int j = 0; j < L; j++) { int d = 0xff & utf8buf[j];