Are angle brackets valid in data URIs?

我们两清 提交于 2019-12-11 08:37:57

问题


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

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

However reading through RFC 2397 I have found the following:

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

where "urlchar" is imported from RFC2396

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:

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.

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


回答1:


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



来源:https://stackoverflow.com/questions/51406819/are-angle-brackets-valid-in-data-uris

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!