Bug 29927

Summary: Http Response doesn't UnescapeDataString
Product: [Mono] Class Libraries Reporter: Adi <avivi.adi.hr>
Component: System.WebAssignee: marcos.henrich
Status: RESOLVED FIXED    
Severity: normal CC: masafa, mono-bugs+mono
Priority: ---    
Version: 4.0.0   
Target Milestone: Untriaged   
Hardware: PC   
OS: Linux   
Tags: Is this bug a regression?: ---
Last known good build:

Description Adi 2015-05-11 05:12:46 UTC
I have to :

public override void OnActionExecuting (System.Web.Http.Controllers.HttpActionContext actionContext)
{
	if (EnvironmentUtils.RunningOnMono) {
		if (actionContext.ActionArguments.ContainsKey ("myId")) {
			actionContext.ActionArguments ["myId"] = Uri.UnescapeDataString((string)actionContext.ActionArguments ["myId"]);
		}
	}
	base.OnActionExecuting (actionContext);
}

Example :
http://myAddress.com:8080/docs/TTSSTT%252F2062

different behaviour in .Net/Windows.
Comment 1 Adi 2015-05-11 05:24:57 UTC
P.S.
mono 4.1.0
ubuntu 14.04.02 LTS
monodevelop 6.0
Comment 2 Adi 2015-05-13 04:52:58 UTC
I can add simple client server code test which demonstrate this bug:

Server :

using System;
using System.Net;
using System.IO;

namespace httpTestServer
{
	class MainClass
	{
		public static void Main (string[] args)
		{
			Console.WriteLine ("Http Test Server");

			if (!HttpListener.IsSupported)
			{
				Console.WriteLine ("Windows XP SP2 or Server 2003 is required to use the HttpListener class.");
				return;
			}
			string prefixes = "http://localhost:12345/";
			HttpListener listener = new HttpListener();
			listener.Prefixes.Add(prefixes);
			listener.Start();

			Console.WriteLine("Listening...");
			HttpListenerContext context = listener.GetContext();

			Console.WriteLine ("{0}\n{1}", context.Request.Url.AbsoluteUri, context.Request.Url.AbsolutePath);

			Stream Answer = context.Request.InputStream;
			StreamReader _Answer = new StreamReader(Answer);
			Console.WriteLine(_Answer.ReadToEnd());

			HttpListenerRequest request = context.Request;
			HttpListenerResponse response = context.Response;
			string responseString = "<HTML><BODY> Hello world!</BODY></HTML>";
			byte[] buffer = System.Text.Encoding.UTF8.GetBytes(responseString);
			response.ContentLength64 = buffer.Length;
			System.IO.Stream output = response.OutputStream;
			output.Write(buffer,0,buffer.Length);
			output.Close();
			listener.Stop();
		}
	}
}



Client :

using System;
using System.Net.Http;
using System.Net;
using System.IO;
using System.Text;

namespace httpTest
{
	class MainClass
	{
		public static void Main (string[] args)
		{
			Console.WriteLine ("HttpRequest Test");
			string key = "Product/1";
			key = Uri.EscapeDataString (key);
			HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://localhost:12345/" + key + "/");
			request.Headers["Accept-Encoding"] = "deflate,gzip";
			request.Headers["grant_type"] = "client_credentials";
			request.Accept = "application/json;charset=UTF-8";
			request.Credentials = CredentialCache.DefaultCredentials;
			request.Method = "PUT";
			(request).UserAgent = ".NET Frame/work Exa/mple Client";
			byte[] byteArray = Encoding.ASCII.GetBytes("/123/456");

			request.ContentLength = byteArray.Length;

			//request.ContentType = "application/x-www-form-urlencoded";
			Stream dataStream = request.GetRequestStream ();


			dataStream.Write (byteArray, 0, byteArray.Length);
			dataStream.Close ();
			request.Headers ["ABC"] = "My/String";
			Console.WriteLine ("request.GetResponse...");
			WebResponse response = request.GetResponse();
			Console.WriteLine ("Done");
			Console.WriteLine (((HttpWebResponse)response).StatusDescription);
			response.Close ();

		}
	}
}




Runing these tests on mono-linux/monodevelop and .net-windows/VS2013 gives different results in the received url (seems .net/win UnescapeDataString automatically ..)
Comment 3 marcos.henrich 2015-06-01 09:36:52 UTC
Hi Adi.

Thank you for the detailed bug report.

The pull request for this issue can be found in the link below.
https://github.com/mono/mono/pull/1845
Comment 4 marcos.henrich 2015-06-01 10:27:25 UTC
Fixed in master 50a1e4ce9db4da27fada7dbdc83b354d2f21f7ca.
https://github.com/mono/mono/commit/50a1e4c