Something of a strange question but let's see what kind of response it gets...
If I code a console app (VS 2013, .NET 4.5.1) and execute this line of code:
Uri.EscapeUriString("[")
I get this:
[
However if I execute the same thing (well, technically Uri.EscapeUriString("[").Dump()
) in LINQPad on my machine I get this:
%5B
To further complicate things, according to this post Uri.EscapeUriString("[")
should indeed return %5B
.The post was written on 27/06/2012.
I'm thinking that perhaps LINQPad is referencing an older DLL than that used by VS, but that would imply that EscapeUriString
has changed relatively recently, which I cannot find any record of. Does anyone have any ideas as to what could be causing this behaviour?
This changed between .Net 4 and .Net 4.5, which you can verify by retargeting the framework version to .Net 4 and running the test program.
.Net 4 -> outputs "%5B" .net 4.5 (or later) -> outputs "["
This is mentioned here: Application Compatibility in the .NET Framework 4.5
under the section for Uri.EscapeDataString , Uri.EscapeUriString, and Uri.UnescapeDataString, which states that (with .Net 4.5):
In particular, it is the EscapeUriString does not escape reserved characters which is significant.
The new behavior seems to be the correct one according to RFC 2396. In line 566 it states:
In Uri.EscapeUriString's documentation it states that
So it would seem that there was a bug up to .NET 4.0 that was fixed in 4.5.1