Return-Path: X-Original-To: apmail-tomcat-dev-archive@www.apache.org Delivered-To: apmail-tomcat-dev-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id D49979DA9 for ; Wed, 16 Nov 2011 13:44:18 +0000 (UTC) Received: (qmail 88589 invoked by uid 500); 16 Nov 2011 13:44:18 -0000 Delivered-To: apmail-tomcat-dev-archive@tomcat.apache.org Received: (qmail 88524 invoked by uid 500); 16 Nov 2011 13:44:17 -0000 Mailing-List: contact dev-help@tomcat.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "Tomcat Developers List" Delivered-To: mailing list dev@tomcat.apache.org Received: (qmail 88515 invoked by uid 99); 16 Nov 2011 13:44:17 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 16 Nov 2011 13:44:17 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 16 Nov 2011 13:44:14 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id AE9F423888CC for ; Wed, 16 Nov 2011 13:43:53 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1202705 - in /tomcat/trunk: java/org/apache/tomcat/util/http/Parameters.java test/org/apache/tomcat/util/http/TestParameters.java Date: Wed, 16 Nov 2011 13:43:53 -0000 To: dev@tomcat.apache.org From: kkolinko@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20111116134353.AE9F423888CC@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: kkolinko Date: Wed Nov 16 13:43:53 2011 New Revision: 1202705 URL: http://svn.apache.org/viewvc?rev=1202705&view=rev Log: Parameters.java: - Fix regression in urldecoding of parameters that contain spaces Patch by Willem Fibbe TestParameters.java: - Improve the test to cover parameters that contain spaces Modified: tomcat/trunk/java/org/apache/tomcat/util/http/Parameters.java tomcat/trunk/test/org/apache/tomcat/util/http/TestParameters.java Modified: tomcat/trunk/java/org/apache/tomcat/util/http/Parameters.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/http/Parameters.java?rev=1202705&r1=1202704&r2=1202705&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/tomcat/util/http/Parameters.java (original) +++ tomcat/trunk/java/org/apache/tomcat/util/http/Parameters.java Wed Nov 16 13:43:53 2011 @@ -266,6 +266,7 @@ public final class Parameters { pos++; break; case '%': + case '+': // Decoding required if (parsingName) { decodeName = true; Modified: tomcat/trunk/test/org/apache/tomcat/util/http/TestParameters.java URL: http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/tomcat/util/http/TestParameters.java?rev=1202705&r1=1202704&r2=1202705&view=diff ============================================================================== --- tomcat/trunk/test/org/apache/tomcat/util/http/TestParameters.java (original) +++ tomcat/trunk/test/org/apache/tomcat/util/http/TestParameters.java Wed Nov 16 13:43:53 2011 @@ -16,6 +16,8 @@ */ package org.apache.tomcat.util.http; +import java.io.UnsupportedEncodingException; +import java.net.URLEncoder; import java.util.Enumeration; import static org.junit.Assert.assertArrayEquals; @@ -24,16 +26,15 @@ import static org.junit.Assert.assertFal import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; -import org.junit.Test; -import org.apache.tomcat.util.buf.UEncoder; +import org.junit.Test; public class TestParameters { private static final Parameter SIMPLE = new Parameter("foo1", "bar1"); private static final Parameter SIMPLE_MULTIPLE = - new Parameter("foo2", "bar1", "bar2"); + new Parameter("foo2", "bar1", "bar2", "hello world", "?%@"); private static final Parameter NO_VALUE = new Parameter("foo3"); private static final Parameter EMPTY_VALUE = @@ -78,7 +79,10 @@ public class TestParameters { @Test public void testInternal() { assertEquals("foo1=bar1", SIMPLE.toString()); - assertEquals("foo2=bar1&foo2=bar2", SIMPLE_MULTIPLE.toString()); + // Note: testing requires that ' ' is encoded as '+', + // because that is what browsers will send us. + assertEquals("foo2=bar1&foo2=bar2&foo2=hello+world&foo2=%3F%25%40", + SIMPLE_MULTIPLE.toString()); assertEquals("foo3", NO_VALUE.toString()); assertEquals("foo4=", EMPTY_VALUE.toString()); } @@ -274,7 +278,6 @@ public class TestParameters { private static class Parameter { private final String name; private final String[] values; - private final UEncoder uencoder = new UEncoder(); public Parameter(String name, String... values) { this.name = name; @@ -291,27 +294,30 @@ public class TestParameters { @Override public String toString() { - StringBuilder result = new StringBuilder(); - boolean first = true; - if (values.length == 0) { - return uencoder.encodeURL(name); - } - for (String value : values) { - if (first) { - first = false; - } else { - result.append('&'); + try { + StringBuilder result = new StringBuilder(); + boolean first = true; + if (values.length == 0) { + return URLEncoder.encode(name, "UTF-8"); } - if (name != null) { - result.append(uencoder.encodeURL(name)); - } - if (value != null) { - result.append('='); - result.append(uencoder.encodeURL(value)); + for (String value : values) { + if (first) { + first = false; + } else { + result.append('&'); + } + if (name != null) { + result.append(URLEncoder.encode(name, "UTF-8")); + } + if (value != null) { + result.append('='); + result.append(URLEncoder.encode(value, "UTF-8")); + } } + return result.toString(); + } catch (UnsupportedEncodingException ex) { + return ex.toString(); } - - return result.toString(); } } } --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org For additional commands, e-mail: dev-help@tomcat.apache.org