Return-Path: Delivered-To: apmail-cxf-issues-archive@www.apache.org Received: (qmail 75064 invoked from network); 30 May 2009 13:23:19 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 30 May 2009 13:23:19 -0000 Received: (qmail 79097 invoked by uid 500); 30 May 2009 13:23:32 -0000 Delivered-To: apmail-cxf-issues-archive@cxf.apache.org Received: (qmail 79049 invoked by uid 500); 30 May 2009 13:23:32 -0000 Mailing-List: contact issues-help@cxf.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cxf.apache.org Delivered-To: mailing list issues@cxf.apache.org Received: (qmail 79039 invoked by uid 99); 30 May 2009 13:23:32 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 30 May 2009 13:23:32 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.140] (HELO brutus.apache.org) (140.211.11.140) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 30 May 2009 13:23:28 +0000 Received: from brutus (localhost [127.0.0.1]) by brutus.apache.org (Postfix) with ESMTP id 5F0D1234C004 for ; Sat, 30 May 2009 06:23:07 -0700 (PDT) Message-ID: <2070563156.1243689787374.JavaMail.jira@brutus> Date: Sat, 30 May 2009 06:23:07 -0700 (PDT) From: "Nacho G. Mac Dowell (JIRA)" To: issues@cxf.apache.org Subject: [jira] Commented: (CXF-2242) FormEncodingProvider writes the application/x-www-form-urlencoded params incorrectly when multiple params with the same name are present In-Reply-To: <1856219005.1243516185690.JavaMail.jira@brutus> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 X-Virus-Checked: Checked by ClamAV on apache.org [ https://issues.apache.org/jira/browse/CXF-2242?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12714709#action_12714709 ] Nacho G. Mac Dowell commented on CXF-2242: ------------------------------------------ Oops... I forgot to include the other it.hasNext()... Currently this test fails: MultivaluedMap mvMap = new MetadataMap(); mvMap.add("a", "a1"); mvMap.add("a", "a2"); ByteArrayOutputStream bos = new ByteArrayOutputStream(); ferp.writeTo(mvMap, MultivaluedMap.class, MultivaluedMap.class, new Annotation[0], MediaType.APPLICATION_FORM_URLENCODED_TYPE, new MetadataMap(), bos); String result = bos.toString(); assertEquals("Wrong value", "a=a1&a=a2", result.toString()); The result is a=a1a=a2 So, it should be....: for (Iterator>> it = map.entrySet().iterator(); it.hasNext();) { Map.Entry> entry = it.next(); for (Iterator entryIterator = entry.getValue().iterator(); entryIterator.hasNext();) { String value = entryIterator.next(); os.write(entry.getKey().getBytes("UTF-8")); os.write('='); String data = encoded ? value : HttpUtils.urlEncode(value); os.write(data.getBytes("UTF-8")); if (entryIterator.hasNext() || it.hasNext()) { os.write('&'); } } } Like this, your test, the prev test and the following will pass: MultivaluedMap mvMap = new MetadataMap(); mvMap.add("a", "a1"); mvMap.add("b", "b1"); mvMap.add("b", "b2"); ByteArrayOutputStream bos = new ByteArrayOutputStream(); ferp.writeTo(mvMap, MultivaluedMap.class, MultivaluedMap.class, new Annotation[0], MediaType.APPLICATION_FORM_URLENCODED_TYPE, new MetadataMap(), bos); String result = bos.toString(); assertEquals("Wrong value", "a=a1&a=a2", result.toString()); Best regards, n > FormEncodingProvider writes the application/x-www-form-urlencoded params incorrectly when multiple params with the same name are present > ---------------------------------------------------------------------------------------------------------------------------------------- > > Key: CXF-2242 > URL: https://issues.apache.org/jira/browse/CXF-2242 > Project: CXF > Issue Type: Bug > Components: REST > Affects Versions: 2.2.1 > Reporter: Nacho G. Mac Dowell > Attachments: FormEncodingProvider.patch > > > Hi, there is a problem with FormEncodingProvider when writing the url-encoded string. It is checking an incorrect iterator. > public void writeTo(MultivaluedMap map, Class c, Type t, Annotation[] anns, > MediaType mt, MultivaluedMap headers, OutputStream os) > throws IOException, WebApplicationException { > boolean encoded = AnnotationUtils.getAnnotation(anns, Encoded.class) != null; > for (Iterator>> it = map.entrySet().iterator(); it.hasNext();) { > Map.Entry> entry = it.next(); > for (String value : entry.getValue()) { > os.write(entry.getKey().getBytes("UTF-8")); > os.write('='); > String data = encoded ? value : HttpUtils.urlEncode(value); > os.write(data.getBytes("UTF-8")); > if (it.hasNext()) { > os.write('&'); > } > } > } > } > it.hasNext() should be checking the entry iterator and not the map iterator. The consequence is that & is never appended if, for example, there is only one parameter > Fixed version would be: > public void writeTo(MultivaluedMap map, Class c, Type t, Annotation[] anns, > MediaType mt, MultivaluedMap headers, OutputStream os) > throws IOException, WebApplicationException { > boolean encoded = AnnotationUtils.getAnnotation(anns, Encoded.class) != null; > for (Iterator>> it = map.entrySet().iterator(); it.hasNext();) { > Map.Entry> entry = it.next(); > for (Iterator entryIterator = entry.getValue().iterator(); entryIterator.hasNext();) { > String value = entryIterator.next(); > os.write(entry.getKey().getBytes("UTF-8")); > os.write('='); > String data = encoded ? value : HttpUtils.urlEncode(value); > os.write(data.getBytes("UTF-8")); > if (entryIterator.hasNext()) { > os.write('&'); > } > } > } > } > I don't have time just now to provide test cases but a careful look should do. > best regards -- This message is automatically generated by JIRA. - You can reply to this email to add a comment to the issue online.