diff options
author | Chris Goldthorpe | 2010-04-01 21:22:33 +0000 |
---|---|---|
committer | Chris Goldthorpe | 2010-04-01 21:22:33 +0000 |
commit | 5ae5529c9109d830b1e0bd2d5287e66f42afe3e7 (patch) | |
tree | 09fa83b7d8e8594cec9bc46f1ea0939305016c32 /org.eclipse.help | |
parent | f919343dda7230ec1c1b08715a5cc4acc985afd0 (diff) | |
download | eclipse.platform.ua-5ae5529c9109d830b1e0bd2d5287e66f42afe3e7.tar.gz eclipse.platform.ua-5ae5529c9109d830b1e0bd2d5287e66f42afe3e7.tar.xz eclipse.platform.ua-5ae5529c9109d830b1e0bd2d5287e66f42afe3e7.zip |
Reduce encryption of scope cookie - [Webapp] Search scope cookie file reaches max size quickly, limits creation of new scopes
Diffstat (limited to 'org.eclipse.help')
-rw-r--r-- | org.eclipse.help/src/org/eclipse/help/internal/util/URLCoder.java | 29 |
1 files changed, 23 insertions, 6 deletions
diff --git a/org.eclipse.help/src/org/eclipse/help/internal/util/URLCoder.java b/org.eclipse.help/src/org/eclipse/help/internal/util/URLCoder.java index 100c7382d..35f9c8403 100644 --- a/org.eclipse.help/src/org/eclipse/help/internal/util/URLCoder.java +++ b/org.eclipse.help/src/org/eclipse/help/internal/util/URLCoder.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2007 IBM Corporation and others. + * Copyright (c) 2000, 2010 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -17,7 +17,15 @@ public class URLCoder { public static String encode(String s) { try { - return urlEncode(s.getBytes("UTF8")); //$NON-NLS-1$ + return urlEncode(s.getBytes("UTF8"), false); //$NON-NLS-1$ + } catch (UnsupportedEncodingException uee) { + return null; + } + } + + public static String compactEncode(String s) { + try { + return urlEncode(s.getBytes("UTF8"), true); //$NON-NLS-1$ } catch (UnsupportedEncodingException uee) { return null; } @@ -31,15 +39,24 @@ public class URLCoder { } } - private static String urlEncode(byte[] data) { + private static String urlEncode(byte[] data, boolean encodeAlphanumeric) { StringBuffer buf = new StringBuffer(data.length); for (int i = 0; i < data.length; i++) { - buf.append('%'); - buf.append(Character.forDigit((data[i] & 240) >>> 4, 16)); - buf.append(Character.forDigit(data[i] & 15, 16)); + byte nextByte = data[i]; + if (encodeAlphanumeric && isAlphaNumeric(nextByte)) { + buf.append((char)nextByte); + } else { + buf.append('%'); + buf.append(Character.forDigit((nextByte & 240) >>> 4, 16)); + buf.append(Character.forDigit(nextByte & 15, 16)); + } } return buf.toString(); } + + private static boolean isAlphaNumeric(byte b) { + return (b >= 0 && b <= 9) || (b >= 'a' && b < 'z') || ( b >= 'A' && b <= 'Z'); + } private static byte[] urlDecode(String encodedURL) { int len = encodedURL.length(); |