关于DataURL不是使用base64编码时,是使用decodeURI解码还是decodeURIComponent

szuzsq 2017-06-09 11:24:40
我做canvans,image时用到DataURL.

encodeURI: 对所有非(基本字符,Mark字符和保留字符)进行编码.
encodeURIComponent: 所有非(基本字符,Mark字符)进行编码.(注:对于保留字符同样做编码)

那我想问,url中的不安全字符到底有哪些啊?
如果DataURL不是使用base64编码时,是使用decodeURI解码还是decodeURIComponent?




------------------------------------------------------------------------------------------------------------------------------------------------------------------------我百度了一下.DataURL的官方解释.贴出来如下,后面是我翻译的,应该理解得差不多了.

------------------------------------------------------------------------------------------------------------------------------------------------------------------------

2. Description

Some applications that use URLs also have a need to embed (small)
media type data directly inline. This document defines a new URL
scheme that would work like 'immediate addressing'. The URLs are of
the form:

data:[<mediatype>][;base64],<data>

The <mediatype> is an Internet media type specification (with
optional parameters.) The appearance of ";base64" means that the data
is encoded as base64. Without ";base64", the data (as a sequence of
octets) is represented using ASCII encoding for octets inside the
range of safe URL characters and using the standard %xx hex encoding
of URLs for octets outside that range. If <mediatype> is omitted, it
defaults to text/plain;charset=US-ASCII. As a shorthand,
"text/plain" can be omitted but the charset parameter supplied.

The "data:" URL scheme is only useful for short values. Note that
some applications that use URLs may impose a length limit; for
example, URLs embedded within <A> anchors in HTML have a length limit
determined by the SGML declaration for HTML [RFC1866]. The LITLEN
(1024) limits the number of characters which can appear in a single

2.描述
某些使用URL的应用程序也需要直接内联嵌入媒体类型数据(短小值).这个文档定义了一个新的URL协议,像'立即寻址'一样工作.格式为:

data:[<mediatype>][;base64],<data>

<mediaType>是网络媒体类型规范(可选参数).
如果出现";base64",表示数据以base64编码.
如果没有";base64",表示数据(8bit构成octet字节序列)编码方式为:如果在安全的url字符范围内,则使用ASCII编码octet字节序列;如果超出安全的url字符范围,则使用标准备的%xx二进制编码octet字节序列.
如果没有<mediatype>,表示网络媒体类型为默认的"text/plain;charset=US-ASCII".缩写时,"text/plain"可以省略,但"charset"参数必须提供.

"data:"URL协议仅适用于短小值的网络媒体类型.
请注意,某些使用URL的应用程序可能会有长度限制.例如,在HTML中嵌入在<a>标签内的URL具有长度限制,由HTML标准通用标记语言SGML文档 [RFC1866]决定.在单个URL中限制长度为LITLEN(1024).
...全文
419 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
hookee 2017-06-20
  • 打赏
  • 举报
回复
encodeURI方法不会对下列字符编码 ASCII字母、数字、~!@#$&*()=:/,;?+' encodeURIComponent方法不会对下列字符编码 ASCII字母、数字、~!*()' 参考 http://www.cnblogs.com/season-huang/p/3439277.html
NANU-NANA 2017-06-20
  • 打赏
  • 举报
回复
这东东,我听过。
szuzsq 2017-06-20
  • 打赏
  • 举报
回复
随便来个绝世美女吧

87,994

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧