用方括号Uri.EscapeUriString [英] Uri.EscapeUriString with square braces

查看:1189
本文介绍了用方括号Uri.EscapeUriString的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一个奇怪的问题,但事情让我们看看它得到了什么样的反应?



如果我编写一个控制台应用程序(VS 2013,.NET 4.5.1 )和执行这行代码:



Uri.EscapeUriString([)



我得到这样的:



[



但是,如果我执行同样的事情(当然,技术上 Uri.EscapeUriString([)。转储())的LINQPad在我的机器,我得到这样的:



%5B



要进一步根据这个帖子 Uri.EscapeUriString([)复杂的事情,的确应该返回%5B .The后写在27/06/2012。



我想着也许LINQPad被引用比由VS使用较旧的DLL,但是这将意味着 EscapeUriString 已相对最近改变了,这是我无法找到任何记录。没有人有任何想法,这可能是导致这种行为?


解决方案

这改变了.NET 4.0和.NET 4.5之间, 。您可以通过重新目标框架版本的.Net 4和运行测试程序验证



.NET 4.0 - >输出%5B
.NET 4.5(或更高版本) - >输出[



这是这里所说:的应用程序在.NET Framework 4.5



下的部分兼容性为的 Uri.EscapeDataString,Uri.EscapeUriString和Uri.UnescapeDataString 的,其中规定,(与.NET 4.5):




的预留和未预留的字符列表现在支持 RFC 3986



具体变化:

 站票转义字符是未逃脱。 
EscapeDataString逃脱基于RFC 3986.
EscapeUriString不逃避保留字符保留字符。如果遇到一个无效的转义序列
UnescapeDataString不会抛出异常。




在特别是,它是<青霉> EscapeUriString不会逃脱保留字符的是显著。


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):

The list of reserved and unreserved characters now supports RFC 3986.

Specific changes:

Unreserved escaped characters are un-escaped.
EscapeDataString escapes reserved characters based on RFC 3986.
EscapeUriString does not escape reserved characters.
UnescapeDataString does not throw an exception if it encounters an invalid escape sequence.

In particular, it is the EscapeUriString does not escape reserved characters which is significant.

这篇关于用方括号Uri.EscapeUriString的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆