Bry*_*eld 5 javascript url encode
我用不同的语言编写自己的函数,如果可能的话,我希望它能提供相同的结果.
简短的答案,您可以匹配encodeURIComponent使用以下代码进行编码的所有UTF-16代码单元:
/[^a-zA-Z0-9\-_.!~*'()]/g
Run Code Online (Sandbox Code Playgroud)
不过,规范说它使用4字节UTF-8编码来处理补充代码点。
ES 262说的很长答案
15.1.3.4 encodeURIComponent(uriComponent)
encodeURIComponent函数计算URI的新版本,其中某些特定字符的每个实例都被一个,两个,三个或四个表示该字符的UTF-8编码的转义序列代替。当使用一个参数uriComponent调用encodeURIComponent函数时,将执行以下步骤:
令componentString为ToString(uriComponent)。
令unescapedURIComponentSet为一个字符串,其中包含在uriUnescaped中有效的每个字符的一个实例 。
返回调用Encode(componentString,unescapedURIComponentSet)的结果
并因此定义了uriUnescaped
uriUnescaped ::: uriAlpha | DecimalDigit | uriMark
哪里
uriAlpha ::: abcdefghijklmnopqrstu vwxyz ABCDEFGHIJKLMNOPQRSTU VWXYZ之一
uriMark :::-_之一。!〜*'()
DecimalDigit ::: 0 1 2 3 4 5 6 7 8 9之一
| 归档时间: |
|
| 查看次数: |
7994 次 |
| 最近记录: |