Bug 29927 - Http Response doesn't UnescapeDataString
Summary: Http Response doesn't UnescapeDataString
Status: RESOLVED FIXED
Alias: None
Product: Class Libraries
Classification: Mono
Component: System.Web ()
Version: 4.0.0
Hardware: PC Linux
: --- normal
Target Milestone: Untriaged
Assignee: marcos.henrich
URL:
Depends on:
Blocks:
 
Reported: 2015-05-11 05:12 UTC by Adi
Modified: 2015-06-01 10:27 UTC (History)
2 users (show)

Tags:
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 GitHub or Developer Community 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 FIXED

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