Bug 7079 - HttpListenerRequest decodes ampersands (%26)
Summary: HttpListenerRequest decodes ampersands (%26)
Alias: None
Product: Class Libraries
Classification: Mono
Component: System ()
Version: master
Hardware: PC Windows
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
Depends on:
Reported: 2012-09-11 18:53 UTC by David Straw
Modified: 2012-09-14 09:12 UTC (History)
2 users (show)

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

NUnit test (728 bytes, text/x-csharp)
2012-09-12 14:40 UTC, David Straw

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:

Description David Straw 2012-09-11 18:53:05 UTC
URIs with an encoded ampersand should not decode the ampersand for HTTP requests.

A request to this URI:

should cause an HttpListenerRequest's Url property to have:
http://localhost:12345/?a=b %26 c&d=e

This allows higher-level components to differentiate between query string parameter delimiters and embedded ampersands. This is how it works in the .NET framework. Right now in Mono, the resulting Url is:

http://localhost:12345/?a=b & c&d=e

which makes it impossible to differentiate the two kinds of ampersands.
Comment 1 David Straw 2012-09-12 14:22:37 UTC
From testing it looks like the Microsoft implementation doesn't decode the URL at all. Removing the HttpUtility.UrlDecode call seems to make it work consistently with .NET in the cases I've tried.

I'll attach my test case and submit a pull request.
Comment 2 David Straw 2012-09-12 14:40:23 UTC
Created attachment 2511 [details]
NUnit test

This test case uses an HttpListener and WebClient to show the behavior. I created the test to work on .NET and Mono, but it would probably be lighter-weight to instantiate the HttpListenerRequest directly in a unit test that's part of mono.