Bug 25819 - Adding a key with square brackets to MultipartFormDataContent raises an Invalid format error
Summary: Adding a key with square brackets to MultipartFormDataContent raises an Inval...
Status: RESOLVED NORESPONSE
Alias: None
Product: Android
Classification: Xamarin
Component: BCL Class Libraries ()
Version: 5.1
Hardware: PC Windows
: Normal normal
Target Milestone: ---
Assignee: Peter Collins
URL:
Depends on:
Blocks:
 
Reported: 2015-01-08 04:45 UTC by alexcassells
Modified: 2017-08-23 21:37 UTC (History)
3 users (show)

Tags: XATriaged
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED NORESPONSE

Description alexcassells 2015-01-08 04:45:17 UTC
Calling the add function on a System.Net.Http.MultipartFormDataContent object with strings containing square brackets throws a System.FormatException when run on Mono for Android.  Running the same code on a Windows Console App this does not throw an exception.

System.FormatException: Invalid format.
  at at System.Net.Http.Headers.NameValueHeaderValue.set_Value (string) <IL 0x00047, 0x00290>
  at at System.Net.Http.Headers.NameValueHeaderValue..ctor (string,string) <IL 0x00015, 0x00097>
  at at System.Net.Http.Headers.CollectionExtensions.SetValue (System.Collections.Generic.List`1<System.Net.Http.Headers.NameValueHeaderValue>,string,string) <IL 0x00064, 0x002d3>
  at at System.Net.Http.Headers.ContentDispositionHeaderValue.SetValue (string,string) <IL 0x0001e, 0x000db>
  at at System.Net.Http.Headers.ContentDispositionHeaderValue.set_Name (string) <IL 0x00007, 0x00053>
  at at System.Net.Http.MultipartFormDataContent.AddContentDisposition (System.Net.Http.HttpContent,string,string) <IL 0x00021, 0x00127>
  at at System.Net.Http.MultipartFormDataContent.Add (System.Net.Http.HttpContent,string) <IL 0x00021, 0x000df>
  at FormDataBug.TestMultiformData.AddTest () [0x00012] in c:\Users\ACassells\Documents\Projects\FormDataBug\FormDataBug\TestMultiformData.cs:12
  at FormDataBug.MainActivity/<>c__DisplayClass1.<OnCreate>b__0 (object,System.EventArgs) [0x00032] in c:\Users\ACassells\Documents\Projects\FormDataBug\FormDataBug\MainActivity.cs:30
  at Android.Views.View/IOnClickListenerImplementor.OnClick (Android.Views.View) [0x0000d] in /Users/builder/data/lanes/monodroid-mlion-monodroid-4.20-series/ba9bbbdd/source/monodroid/src/Mono.Android/platforms/android-21/src/generated/Android.Views.View.cs:2020
  at Android.Views.View/IOnClickListenerInvoker.n_OnClick_Landroid_view_View_ (intptr,intptr,intptr) [0x00011] in /Users/builder/data/lanes/monodroid-mlion-monodroid-4.20-series/ba9bbbdd/source/monodroid/src/Mono.Android/platforms/android-21/src/generated/Android.Views.View.cs:1987
  at at (wrapper dynamic-method) object.89bf341c-a623-4b1d-a589-a2f3458c24a8 (intptr,intptr,intptr) <IL 0x00017, 0x00043>

This is an example class that demonstrates this error.

/////////////////////////////////////////////////////
using System;
using System.Net.Http;

namespace FormDataBug
{
	public class TestMultiformData
	{
		public static MultipartFormDataContent AddTest ()
		{
			var content = new MultipartFormDataContent();
			StringContent testItem = new StringContent("Test");
			// This line will raise the Exception
			content.Add(testItem, "Test[0]");
			return content;
		}
	}
}
////////////////////////////////////////////////////

This is important in integrating to an MVC site as MVC structures collections of objects using "objectName[index]" within the MVC model binder.
Comment 1 Udham Singh 2015-01-08 06:46:45 UTC
I have checked this issue with the help of code provided in bug description and able to reproduce this issue. Please refer the screencast : http://www.screencast.com/t/CO4V2tY9T0z

Application Output Log : https://gist.github.com/Udham1/b3a586471cadc0e3d589
Ide Log : https://gist.github.com/Udham1/e081b79abdf30f3aa71a

Environment Info : 

=== Xamarin Studio ===

Version 5.7 (build 661)
Installation UUID: 3235da96-1cb2-43d5-a836-234fd96911c2
Runtime:
	Microsoft .NET 4.0.30319.18449
	GTK+ 2.24.22 (MS-Windows theme)
	GTK# 2.12.26

=== Xamarin.Android ===

Version: 4.20.0 (Enterprise Edition)
Android SDK: D:\Backup_OldMachine\D Drive\SDK\android-sdk
	Supported Android versions:
		1.6    (API level 4)
		2.1    (API level 7)
		2.2    (API level 8)
		2.3    (API level 10)
		3.1    (API level 12)
		4.0    (API level 14)
		4.0.3  (API level 15)
		4.1    (API level 16)
		4.2    (API level 17)
		4.3    (API level 18)
		4.4    (API level 19)
		4.4.87 (API level 20)
Java SDK: C:\Program Files\Java\jdk1.7.0_67
java version "1.7.0_67"
Java(TM) SE Runtime Environment (build 1.7.0_67-b01)
Java HotSpot(TM) 64-Bit Server VM (build 24.65-b04, mixed mode)

=== Build Information ===

Release ID: 507000661
Git revision: b70bab61da996da29045ea8ee8aed1a6faedbe78
Build date: 2015-01-05 11:27:37-05
Xamarin addins: 82f6c71490562d6cd125a09287f441902fdac3d7

=== Operating System ===

Windows 6.2.9200.0 (64-bit)
Comment 2 Marek Habersack 2016-08-30 21:44:18 UTC
@peter, can you guys create a sample project for this, please, and then re-assign the bug to me? Thanks!
Comment 3 Cody Beyer (MSFT) 2017-08-23 21:37:16 UTC
Because we have not received a reply to our request for more information we are closing this issue. If you are still encountering this issue, please reopen the ticket with the requested information. Thanks!