尖括号在数据URI中是否有效? [英] Are angle brackets valid in data URIs?

查看:258
本文介绍了尖括号在数据URI中是否有效?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在阅读数据URI ,其中包含有效数据URI的以下示例:

I've been reading about Data URIs which has the following example of a valid data URI:

data:text/html,<script>alert('hi');</script>

但是通读 RFC 2397 我发现了以下内容:

However reading through RFC 2397 I have found the following:

dataurl    := "data:" [ mediatype ] [ ";base64" ] "," data
mediatype  := [ type "/" subtype ] *( ";" parameter )
data       := *urlchar
parameter  := attribute "=" value

其中"urlchar"是从 RFC2396

据我了解,urlchar应该是部分中的内容RFC2396的2.4.3 ,其中记录了已排除的US-ASCII字符列表,并特别指出:

From what I understood is that urlchar should be what is in Section 2.4.3 of RFC2396, where it notes the list of US-ASCII characters that have been excluded and specifically says:

尖括号<"和>"和双引号()字符是 排除,因为它们通常用作URI中的定界符 文本文档和协议字段.

The angle-bracket "<" and ">" and double-quote (") characters are excluded because they are often used as the delimiters around URI in text documents and protocol fields.

所以我的问题是,数据URL中是否允许使用尖括号?是我误解了RFC还是 MDN 中的示例>错了吗?

So my question is, are angle brackets allowed in Data URLs? Am I misinterpreting the RFC or is the example at MDN wrong?

推荐答案

该示例确实是错误的(因为Data URI无效,尽管它可能起作用").

The example is indeed wrong (in that the Data URI is invalid, although it might "work").

这篇关于尖括号在数据URI中是否有效?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆