[FIXED HUDSON-5155] in 1.342. The root cause of the problem is that the backing byte[] of ByteBuffer can be bigger than the actual current content that's on it --- in the case of the reporter he got byte[3] as the backing buffer when only two bytes of it is in use.

git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@25962 71c3de6d-444a-0410-be80-ed276b4c234a
This commit is contained in:
kohsuke committed 2010-01-16 15:23:55 +00:00
1 parent e816e08552
commit b39cc4d55e
1 file changed
+4 -1
+4 -1
View File
@@ -64,6 +64,7 @@ import java.net.InetAddress;
import java.net.UnknownHostException;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.ByteBuffer;
import java.nio.CharBuffer;
import java.nio.charset.CharacterCodingException;
import java.nio.charset.CharsetEncoder;
@@ -745,7 +746,9 @@ public class Util {
buf.put(0,c);
buf.rewind();
try {
for (byte b : enc.encode(buf).array()) {
ByteBuffer bytes = enc.encode(buf);
while (bytes.hasRemaining()) {
byte b = bytes.get();
out.append('%');
out.append(toDigit((b >> 4) & 0xF));
out.append(toDigit(b & 0xF));