You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@cxf.apache.org by "Sergey Beryozkin (JIRA)" <ji...@apache.org> on 2009/06/01 19:43:07 UTC
[jira] Resolved: (CXF-2242) FormEncodingProvider writes the
application/x-www-form-urlencoded params incorrectly when multiple params
with the same name are present
[ https://issues.apache.org/jira/browse/CXF-2242?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Sergey Beryozkin resolved CXF-2242.
-----------------------------------
Resolution: Fixed
Fix Version/s: 2.2.3
I applied your proposed fix as is and it worked really well, thanks ! I'd like to view it as a patch point.
> 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
> Assignee: Sergey Beryozkin
> Fix For: 2.2.3
>
> 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<String, String> map, Class<?> c, Type t, Annotation[] anns,
> MediaType mt, MultivaluedMap<String, Object> headers, OutputStream os)
> throws IOException, WebApplicationException {
> boolean encoded = AnnotationUtils.getAnnotation(anns, Encoded.class) != null;
> for (Iterator<Map.Entry<String, List<String>>> it = map.entrySet().iterator(); it.hasNext();) {
> Map.Entry<String, List<String>> 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<String, String> map, Class<?> c, Type t, Annotation[] anns,
> MediaType mt, MultivaluedMap<String, Object> headers, OutputStream os)
> throws IOException, WebApplicationException {
> boolean encoded = AnnotationUtils.getAnnotation(anns, Encoded.class) != null;
> for (Iterator<Map.Entry<String, List<String>>> it = map.entrySet().iterator(); it.hasNext();) {
> Map.Entry<String, List<String>> entry = it.next();
> for (Iterator<String> 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.