HTML5ではform要素のaction属性に空文字を指定できなくなる

4月5日にHTML5草案が更新(W3C) されました。

前回(2011年1月13日版)からの変更点を見ると、こんなものが。

The action and formaction attributes are no longer allowed to have the empty string as value.

5.1. Changes since 13 January 2011(W3C)

action属性と、HTML5で新登場のformaction属性の値に空文字を指定できなくなったようです。

  • HTML4では、action属性の値は%URI;(W3C) となっていて、空文字が許容されています。

また、空文字によるURLがどういう扱いを受けるかは、RFC3986の4.4. Same-Document Reference(tools.ietf.org) にて次のように定義されています。

When a URI reference refers to a URI that is, aside from its fragment component (if any), identical to the base URI (Section 5.1), that reference is called a "same-document" reference. The most frequent examples of same-document references are relative references that are empty or include only the number sign ("#") separator followed by a fragment identifier.

すなわち、<form action=""> とした場合、通常はその文書自身のURIが送信先となり、base要素があるときはそこで指定された基本URI(Base URI)となるはずです。しかし、実際は多くのブラウザが base 要素が指定されていても文書自身のURLを示すようになっており、HTML5では

If action is the empty string, let action be the document's address of the form document.

Note: This step is a willful violation of RFC 3986, which would require base URL processing here. This violation is motivated by a desire for compatibility with legacy content. [RFC3986]

4.10.22.3 Form submission algorithm(W3C)

と、わざわざ注釈付きで「RFC3986に違反するが、互換性のためBase URL処理は行わない」と書かれています。

いずれにしても、今後は空文字を指定するのは避けた方がよさそうですね。