对编码内容多次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) ...
随机推荐
- js的单例
对于 JS 来说,巨大的灵活性使得其可以有多种方式实现单例模式,使用闭包方式来模拟私有数据,按照其思路可得: var single = (function(){ var unique; functi ...
- HTML+css 文字只显示一行
电脑端 设置行高,超出隐藏 p{ width: 80%; height: 16px; line-height: 16px; display: block; overflow: hidden; text ...
- ASA 5.0/8.0/9.0 杂记
ASA 10.0 之前的版本都是使用odbc方式连接,由于某个项目的需求,无奈学习一下这些老掉牙的技巧. 1.新建 数据源 (不会的话,自行搜索一下) 2.使用 快捷方式 或者 其他方式 执行 C:\ ...
- 谁能笑到最后,约瑟夫环-Josephus问题求解
一. 简述Josephus问题 N个人站成一环,从1号开始,用刀将环中后面一个人“消灭“”掉,之后再将刀递给下一个人,这样依次处理,最后留下一个幸存者. 二. 求解方法 1. 约瑟夫问题如果使用 ...
- BZOJ:2763-[JLOI2011]飞行路线(最短路分层图)
题目链接:https://www.lydsy.com/JudgeOnline/problem.php?id=2763 解题心得: 第一次见到分层最短路.其实题中说选择k条路径免费,那怎么选k条路径并没 ...
- Java——异常处理---18.11.14
异常时程序中会有一些错误,但并不是所有的错误都是异常,并且错误有时候是可以避免的. 比如说,你的代码少了一个分号,那么运行出来结果是提示是错误 java.lang.Error: 如果你用 System ...
- google friendly testing
https://www.google.com/webmasters/tools/mobile-friendly/?mc_cid=cc21b18877&mc_eid=cf2bbeb9b2 htt ...
- IDEA阿里Java规范插件的安装
本文参考自阿飞博客:http://www.cnblogs.com/aflyun/p/7668306.html 官方使用教程:https://zhuanlan.zhihu.com/p/30191998? ...
- MySQL高级第三章——查询截取分析
一.查询分析 1.永远小表驱动大表 使用小的数据集驱动大的数据集. //复习 EXISTS 的知识:SELECT ... FROM tb WHERE EXISTS (subquery) 是因为前后数据 ...
- 北京Uber优步司机奖励政策(4月2日)
滴快车单单2.5倍,注册地址:http://www.udache.com/ 如何注册Uber司机(全国版最新最详细注册流程)/月入2万/不用抢单:http://www.cnblogs.com/mfry ...