From 5ae5529c9109d830b1e0bd2d5287e66f42afe3e7 Mon Sep 17 00:00:00 2001 From: Chris Goldthorpe Date: Thu, 1 Apr 2010 21:22:33 +0000 Subject: Reduce encryption of scope cookie - [Webapp] Search scope cookie file reaches max size quickly, limits creation of new scopes --- .../org/eclipse/help/internal/util/URLCoder.java | 29 +++++++++++++++++----- 1 file changed, 23 insertions(+), 6 deletions(-) (limited to 'org.eclipse.help') 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(); -- cgit v1.2.1