对编码内容多次UrlDecode,并不会影响最终结果。

尝试阅读了微软的源代码,不过不容易读懂。

网址:https://referencesource.microsoft.com/#System/net/System/Net/WebUtility.cs,73c04b8a4fde5039

以下为从网址上复制下来的一些关键代码,不过没看懂。

public static string UrlDecode(string encodedValue)
{
if (encodedValue == null)
return null; return UrlDecodeInternal(encodedValue, Encoding.UTF8);
}
private static string UrlDecodeInternal(string value, Encoding encoding)
{
if (value == null)
{
return null;
} int count = value.Length;
UrlDecoder helper = new UrlDecoder(count, encoding); // go through the string's chars collapsing %XX and
// appending each char as char, with exception of %XX constructs
// that are appended as bytes for (int pos = ; pos < count; pos++)
{
char ch = value[pos]; if (ch == '+')
{
ch = ' ';
}
else if (ch == '%' && pos < count - )
{
int h1 = HexToInt(value[pos + ]);
int h2 = HexToInt(value[pos + ]); if (h1 >= && h2 >= )
{ // valid 2 hex chars
byte b = (byte)((h1 << ) | h2);
pos += ; // don't add as char
helper.AddByte(b);
continue;
}
} if ((ch & 0xFF80) == )
helper.AddByte((byte)ch); // 7 bit have to go as bytes because of Unicode
else
helper.AddChar(ch);
} return helper.GetString();
}
 internal void AddChar(char ch)
{
if (_numBytes > )
FlushBytes(); _charBuffer[_numChars++] = ch;
}
  internal void AddByte(byte b)
{
if (_byteBuffer == null)
_byteBuffer = new byte[_bufferSize]; _byteBuffer[_numBytes++] = b;
}
 internal String GetString()
{
if (_numBytes > )
FlushBytes(); if (_numChars > )
return new String(_charBuffer, , _numChars);
else
return String.Empty;
}
String(_charBuffer, 0, _numChars);是看不到源代码的,到这里已经变成一行看不懂的代码
        // Creates a new string from the characters in a subarray.  The new string will
// be created from the characters in value between startIndex and
// startIndex + length - 1.
//
[System.Security.SecuritySafeCritical] // auto-generated
[ResourceExposure(ResourceScope.None)]
[MethodImplAttribute(MethodImplOptions.InternalCall)]
public extern String(char [] value, int startIndex, int length);

下一步应该怎么办,只能希望某个大牛指点下了……

 

对编码内容多次UrlDecode的更多相关文章

  1. python中Url链接编码处理(urlencode,urldecode)

    做完了flask-web应用,这几天想用爬虫做个好玩的电影链接整合器,平时找电影都是在dytt或者dy2018之类的网站,在用dytt搜索电影<美国队长时>,发现他的搜索链接是这样的:ht ...

  2. python2与python3 字符问题以及 字符编码 内容总结

    python2与python3默认编码: python2:gbk                   print( u'上' )     操作系统也是 gbk    python3:unicode p ...

  3. 20140115-URL编码与解码

    UrlEncode()方法,有两个类都有这个方法即HttpUtility.UrlEncode和Server.UrlEncode 区别: 1.HttpUtility.UrlEncode,HttpUtil ...

  4. 百度ueditor新增的将word内容导入到富文本编辑框的功能.

    如何做到 ueditor批量上传word图片? 1.前端引用代码 <!DOCTYPEhtmlPUBLIC"-//W3C//DTD XHTML 1.0 Transitional//EN& ...

  5. UEditor可以如何直接复制word的图文内容到编辑器中

    如何做到 ueditor批量上传word图片? 1.前端引用代码 <!DOCTYPEhtmlPUBLIC"-//W3C//DTD XHTML 1.0 Transitional//EN& ...

  6. URLEncode和URLDecode

    URLEncode.encode(String s,String utf-8) 编码 URLDEcode.decode(String %2b%,String utf-8) 解码 用法: String ...

  7. 【字符编码】Java字符编码详细解答及问题探讨

    一.前言 继上一篇写完字节编码内容后,现在分析在Java中各字符编码的问题,并且由这个问题,也引出了一个更有意思的问题,笔者也还没有找到这个问题的答案.也希望各位园友指点指点. 二.Java字符编码 ...

  8. 中文乱码?不,是 HTML 实体编码!

    When question comes 在 如何用 Nodejs 分析一个简单页面 一文中,我们爬取了博客园首页的 20 篇文章标题,输出部分拼接了一个字符串: var $ = cheerio.loa ...

  9. 各种url编码

    URLENCODE和URLDECODE是比较常用的URL参数转换方法,为以后使用方便,自己归类一下.   一.JavaScript: 编码:encodeURIComponent(URIString)  ...

随机推荐

  1. tornado用户指引(三)------tornado协程使用和原理(二)

    Python3.5  async和await async和await是python3.5引入的2个新的关键字(用这两个关键字编写的函数也称之为"原生协程"). 从tornado4. ...

  2. Python入门 —— 02基础语法

    基础语法入门学习推荐: 简明 Python 教程 下文仅为入门推荐书籍的补充与重点 多行语句:末尾使用斜杠 (  ) ,将一行分为多行 var = item1 + item2 + item3 注释: ...

  3. button onclick实现跳转的常用方法

    1.onclick="javascript:window.location.href='aa.htm' " 2.onclick="location='URL' " ...

  4. [Doctrine Migrations] 数据库迁移组件的深入解析三:自定义数据字段类型

    自定义type 根据官方文档,新建TinyIntType类,集成Type,并重写getName,getSqlDeclaration,convertToPHPValue,getBindingType等方 ...

  5. Spring Cloud之 Config Server 使用ip端口号配置高可用

    先看官方文档的配置 --- spring: profiles: peer1 eureka: instance: hostname: peer1 client: serviceUrl: defaultZ ...

  6. Docker之centos 简单安装

    centos6因为系统自带的可执行的应用程序与 docker 包名字发生冲突,所以重新命名 docker 的RPM包名字为 docker-io. 首先卸载docker包 sudo yum -y rem ...

  7. FPGA软硬协同设计学习笔记及基础知识(一)

    一.FPGA软件硬件协同定义: 软件:一般以软件语言来描述,类似ARM处理器的嵌入式设计.硬件定义如FPGA,里面资源有限但可重配置性有许多优点,新的有动态可充配置技术. Xilinx开发了部分动态可 ...

  8. HDOJ:1533-Going Home(最小费用流)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1533 解题心得: 第一次写最小费用流的题,去hdoj上找了一个入门级题目,建图比较简单,用了spfa和 ...

  9. SpspringBoot日志logback-spring.xml分环境

    SpspringBoot日志logback-spring.xml分环境 2017年08月02日 03:05:13 cqqianyi1 阅读数:30563 标签: logback slf4j sprin ...

  10. python 函数定义顺序

    #!/usr/bin/python # Hello World def order(): print("haha") print('Hello World!') order()