对编码内容多次UrlDecode
对编码内容多次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的更多相关文章
- python中Url链接编码处理(urlencode,urldecode)
做完了flask-web应用,这几天想用爬虫做个好玩的电影链接整合器,平时找电影都是在dytt或者dy2018之类的网站,在用dytt搜索电影<美国队长时>,发现他的搜索链接是这样的:ht ...
- python2与python3 字符问题以及 字符编码 内容总结
python2与python3默认编码: python2:gbk print( u'上' ) 操作系统也是 gbk python3:unicode p ...
- 20140115-URL编码与解码
UrlEncode()方法,有两个类都有这个方法即HttpUtility.UrlEncode和Server.UrlEncode 区别: 1.HttpUtility.UrlEncode,HttpUtil ...
- 百度ueditor新增的将word内容导入到富文本编辑框的功能.
如何做到 ueditor批量上传word图片? 1.前端引用代码 <!DOCTYPEhtmlPUBLIC"-//W3C//DTD XHTML 1.0 Transitional//EN& ...
- UEditor可以如何直接复制word的图文内容到编辑器中
如何做到 ueditor批量上传word图片? 1.前端引用代码 <!DOCTYPEhtmlPUBLIC"-//W3C//DTD XHTML 1.0 Transitional//EN& ...
- URLEncode和URLDecode
URLEncode.encode(String s,String utf-8) 编码 URLDEcode.decode(String %2b%,String utf-8) 解码 用法: String ...
- 【字符编码】Java字符编码详细解答及问题探讨
一.前言 继上一篇写完字节编码内容后,现在分析在Java中各字符编码的问题,并且由这个问题,也引出了一个更有意思的问题,笔者也还没有找到这个问题的答案.也希望各位园友指点指点. 二.Java字符编码 ...
- 中文乱码?不,是 HTML 实体编码!
When question comes 在 如何用 Nodejs 分析一个简单页面 一文中,我们爬取了博客园首页的 20 篇文章标题,输出部分拼接了一个字符串: var $ = cheerio.loa ...
- 各种url编码
URLENCODE和URLDECODE是比较常用的URL参数转换方法,为以后使用方便,自己归类一下. 一.JavaScript: 编码:encodeURIComponent(URIString) ...
随机推荐
- Array方法学习小结
原生js forEach()和map()遍历 A:相同点: 1.都是循环遍历数组中的每一项. 2.forEach() 和 map() 里面每一次执行匿名函数都支持3个参数:数组中的当前项item,当前 ...
- obfuscator-llvm Theos 集成配置
之前我写过一篇文章是关于在 Xcode 里怎么集成配置 obfuscator-llvmobfuscator-llvm Xcode集成配置 有些情况下我们使用 Theos 开发 tweak,需要将 ob ...
- Cab 安装不成功问题
使用 iexpress.exe 成功打包了cab文件. 可下面问题来了,用静态的html调用,提示安装. 确认安装之后,却提示找不到相应的*.ocx,导致无法安装文件到系统 分析具体原因:*.ocx ...
- Linux入门——vsftpd
vsftpd Introduction vsftpd是一款在Linux发行版中最受推崇的FTP服务器程序.特点是小巧轻快,安全易用. vsftpd 的名字代表"very secure FTP ...
- 大数据技术原理与应用——分布式文件系统HDFS
分布式文件系统概述 相对于传统的本地文件系统而言,分布式文件系统(Distribute File System)是一种通过网络实现文件在多台主机上进行分布式存储的文件系统.分布式文件系统的设计一般采用 ...
- Python在线编程环境
除了安装Python的IDE之外,也可以使用在网页中随时随地编写Python程序. Python官网:https://www.python.org/shell Python123:https://py ...
- 反射之三种class对象的获取方法
package www.bit.tech; public class Fanshe1 { } package www.bit.tech; import www.bit.tech.Fanshe1; cl ...
- python note 001
.tilte() .upper() .lower() --- \n \t --- "apple"+" "+"pen" --- .strip( ...
- 记springboot+mybatis+freemarker+bootstrap的使用(2)
二.springboot+mybatis的使用 1.springboot的注解:@SpringBootApplication :启动项目:整合常用注解(@Configuration,@EnableAu ...
- ACM数论-欧几里得与拓展欧几里得
ACM数论——欧几里得与拓展欧几里得 欧几里得算法: 欧几里德算法又称辗转相除法,用于计算两个整数a,b的最大公约数. 基本算法:设a=qb+r,其中a,b,q,r都是整数,则gcd(a,b)=gcd ...