Re: Right paren in urls

Jon Degenhardt writes:
 > A minor syntax question: What are the legal ways specify urls containing
 > right
 > parentheses? Right parentheses are "safe" characters in urls and don't
 > need
 > to encoded, but they are also the termination character in style sheet
 > url
 > references. 
 > My guess is that unencoded right parens would be legal in quoted urls,
 > and
 > illegal in unquoted urls. For example:
 >    Legal:    BODY { background: url("right)paren.gif") }
 >    Legal:    BODY { background: url('right)paren.gif') }
 >    Illegal:  BODY { background: url(right)paren.gif) }
 > However, this isn't clear to me from the style sheet specs. The lex
 > grammar
 > in Appendix B of 7/26/96 CSS-1 Working Draft doesn't handle any of these
 > cases.
 > This suggests all three forms may be illegal. The lex form from the
 > draft is:
 >    "url("[^\n)]+")"        {yylval.str = noquotes(yytext+3); return
 > URL;}
 > This terminates the url at the first right paren, in a quoted string or
 > not.

Good point. The Lex expression is indeed wrong.

The safe way to use a literal parenthesis, in a URL or elsewhere, is
to escape it with a backslash. Section 7.2 ("parsing conventions")
explains that any character can be escaped with a backslash to remove
its special meaning. The way to write the URL is thus:

    BODY { background: url(right\)paren.gif) }

and the Lex rule should be:


I must admit we didn't think of putting quotes around URLs that are
already inside parentheses. Quotes do remove the special meaning of
parentheses, so maybe we should indeed allow

    BODY { background: url("right)paren.gif") }
    BODY { background: url('right)paren.gif') }

as well. Have to think about that one...

  Bert Bos                                ( W 3 C ) http://www.w3.org/
  http://www.w3.org/pub/WWW/People/Bos/                      INRIA/W3C
  bert@w3.org                             2004 Rt des Lucioles / BP 93
  +33 93 65 77 71                 06902 Sophia Antipolis Cedex, France

Follow-Ups: References: