Brackets and parentheses in URLs/URIs in CSS

David Dorward wrote to the W3C CSS-validator list 
<mailto:www-validator-css@w3.org> on 11 April 2005 in “Brackets in URLs 
(was FW: bug.)” (<mid:20050411134529.GD21658@us-lot.org>, 
<http://www.w3.org/mid/20050411134529.GD21658@us-lot.org>):

> On Mon, Apr 11, 2005 at 02:41:45PM +0100, Will Barker wrote:
> [...]
>>url(../images/cms/hondatopbar(1).jpg)
> [...]
> 
> Brackets are not allowed in URLs. That should be represented as:
> ../images/cms/hondatopba%281%29.jpg

Parentheses are allowed as reserved URI characters in the Internet 
standard “Uniform Resource Identifier (URI): Generic Syntax” 
(<urn:ietf:rfc:3986>, <http://www.ietf.org/rfc/rfc3986.txt>, or in your 
RFC repository of choice). The relevant rule follows.

    sub-delims    = "!" / "$" / "&" / "'" / "(" / ")"
                  / "*" / "+" / "," / ";" / "="

The URI-syntax standard also permits square brackets as delimiters for 
certain Internet Protocol addresses (IP addresses). The relevant rule 
follows.

    IP-literal    = "[" ( IPv6address / IPvFuture  ) "]"

Because parentheses and brackets are reserved characters in URIs, 
escaping parentheses and brackets at the URI level changes the formal 
semantics. The operational semantics might stay the same for a while, 
but authors should not rely on such behavior.

Still there is the issue of parentheses in an unquoted URI in a 
Cascading Style Sheet. Escaping at the CSS level provides an easy 
solution without changing any of the URI’s semantics. The following 
example meets all the technical needs of URI and of CSS.

    url(../images/cms/hondatopbar\(1\).jpg)

Square brackets in URIs in CSS do not need CSS escaping.

Curly braces must not appear in URIs. Authors can represent curly braces 
in URIs by escaping at the URI level, like the following example shows.

    url(%7B%7D)

-- 
Etan Wexler.

Received on Thursday, 7 July 2005 04:00:48 UTC