简体   繁体   English

CSS中的非引用数据URI是否有效?

[英]Are unquoted data URIs valid in CSS?

#something {
    background: url(data:image/png;base64,ABCDEF);
}

This snippet works in all browsers which support data URIs (obviously with something else than ABCDEF). 此代码段适用于所有支持数据URI的浏览器(显然不包含ABCDEF)。

Also, it's valid according to the CSS 2.1 spec : 此外,根据CSS 2.1规范 ,它是有效的:

... optional single quote (') or double quote (") character followed by the URI itself... ... 可选的单引号(')或双引号(“)字符后跟URI本身......

But the validator won't accept it without quotes: 验证者不会在没有引号的情况下接受它:

Value Error : background url(data:image/png;base64,ABCDEF) is an incorrect URL 值错误:后台URL(数据:image / png; base64,ABCDEF)是一个不正确的URL

If you surround the URI with single or double quotes, it validates. 如果您使用单引号或双引号括起URI,则会进行验证。

Am I missing something? 我错过了什么吗? Is it a bug in the validator? 它是验证器中的错误吗? EDIT : it was ! 编辑它是

As long as the URI itself does not break the url() syntax in any way (eg ( and ) must either be escaped or URI-encoded so they don't prematurely end the function token, also mentioned in the spec), it should be valid even if unquoted. 只要URI本身不以任何方式破坏url()语法(例如()必须被转义或URI编码,因此它们不会过早地结束函数令牌,也在规范中提到),它应该即使没有引用也是有效的。

It's probably a validator bug. 这可能是一个验证错误。 Specifically, it doesn't appear to handle unquoted data URIs in any form, because when I simply change data to http (even though it obviously doesn't resemble a typical HTTP address): 具体来说,它似乎不会以任何形式处理不带引号的数据URI,因为当我只是将data更改为http (即使它显然不像典型的HTTP地址):

#something {
    background: url(http:image/png;base64,ABCDEF);
}

... it then magically passes validation. ......然后神奇地通过验证。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM