IRI是否可以作为HTML属性值使用? [英] Are IRIs valid as HTML attribute values?

查看:95
本文介绍了IRI是否可以作为HTML属性值使用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用包含非ASCII字符的IRI代替URI作为属性值(例如,对于href属性)是否是有效的HTML? HTML样式(HTML和XHTML,第4和第5种)之间是否有区别?至少 RFC 3986 似乎暗示不是.

Is it valid HTML to use IRIs containing non-ASCII characters as attribute values (e.g. for href attributes) instead of URIs? Are there any differences among the HTML flavors (HTML and XHTML, 4 and 5)? At least RFC 3986 seems to imply that it isn't.

我意识到,使用百分比编码可能会更安全(相对于较旧且IRI不知道的软件),但是我正在寻找有关该标准的明确答案.

I realize that it would probably be safer (regarding older and IRI-unaware software) to use percent encoding, but I'm looking for a definitive answer with regards to the standard.

到目前为止,我已经使用 W3C验证器和URI中未转义的unicode字符进行了一些测试不会使用HTML 4/5和XHTML 4/5文档类型触发任何警告或错误(但是,当然,如果没有错误消息,则并不意味着就没有错误).

So far, I've done some tests with the W3C validator, and unescaped unicode characters in URIs don't trigger any warnings or errors with HTML 4/5 and XHTML 4/5 doctypes (but of course the absence of error messages doesn't imply the absence of errors).

至少chrome还支持原始UTF-8 IRI,但是在触发HTTP请求之前先对其进行转义.另外,我的Web服务器(lighttpd)似乎在HTTP请求中以百分比编码以及未编码形式支持UTF-8字符.

At least chrome also supports raw UTF-8 IRIs, but percent-escapes them before firing an HTTP request. Also, my web server (lighttpd) seems to support UTF-8 characters in their percent-encoded as well as in unencoded form in an HTTP request.

推荐答案

HTML 4.01非常简单.不同的属性对其包含的内容具有不同的规则,但是如果我们要处理<a>元素上的href属性,则

HTML 4.01 is straightforward enough. Different attributes have different rules as to what they can contain, but if we're dealing with the href attribute on an <a> element, then the HTML 4 spec, section B.2.1 Non-ASCII characters in URI attribute values says:

...以下href值是非法的:

... the following href value is illegal:

<A href="http://foo.org/Håkon">...</A>

HTML5是不同的.它说 IRI是有效的,前提是它们符合其他一些规定条件.

HTML5 is different. It says IRIs are valid providing they comply with some additional conditions.

如果满足以下至少一项条件,则URL是有效的URL 持有:

A URL is a valid URL if at least one of the following conditions holds:

  • URL是有效的URI引用[RFC3986].

  • The URL is a valid URI reference [RFC3986].

URL是有效的IRI引用,没有查询组件. [RFC3987]

The URL is a valid IRI reference and it has no query component. [RFC3987]

URL是有效的IRI引用,其查询组件不包含未转义的非ASCII字符. [RFC3987]

The URL is a valid IRI reference and its query component contains no unescaped non-ASCII characters. [RFC3987]

URL是有效的IRI引用,URL文档的字符编码为UTF-8或UTF-16编码. [RFC3987]

The URL is a valid IRI reference and the character encoding of the URL's Document is UTF-8 or a UTF-16 encoding. [RFC3987]

XHTML 1.x遵循与HTML 4.01相同的规则.

XHTML 1.x follows the same rules as HTML 4.01.

XHTML5与HTML5相同.

XHTML5 is the same as HTML5.

这篇关于IRI是否可以作为HTML属性值使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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