esharris has asked for the wisdom of the Perl Monks concerning the following question:

In CGI.pm, the query_string subroutines separates pairs with SEMI-COLONS, by default. But my version of MIE still expects ampersands. Which browser uses the newstyle urls? Shouldn't ampersand be the default?

20040414 Edit by BazB: Changed title from 'Why does CGI::query_string make ampersands the rule, not the exception?'

  • Comment on Why does CGI::query_string make semicolons the rule, not the exception?

Replies are listed 'Best First'.
Re: Why does CGI::query_string make semicolons the rule, not the exception?
by adrianh (Chancellor) on Apr 13, 2004 at 14:43 UTC
    But my version of MIE still expects ampersands. Which browser uses the newstyle urls?

    All browsers support ';' in URLs. It's the application running on the web server that will or will not support ';' vs '&' to separate CGI key/value pairs.

    Shouldn't ampersand be the default?

    I don't think so. The problem with using & is that it should be escaped in XHTML as &. Since people forget to do this all of the time you get a lot of invalid XHTML around. Using ';' solves the problem.

    Since applications built with CGI do support using ';' it makes sense for this to be the default.

Re: Why does CGI::query_string make semicolons the rule, not the exception?
by eserte (Deacon) on Apr 13, 2004 at 14:49 UTC
    It's not the browser which processes the querystring separator, it's the server side which needs to know to process the semicolon. So if you're using a recent CGI.pm or Apache.pm on the server side, everything's fine. But there's a lot of other CGI processing modules (mostly for other languages) which cannot process the semicolon separator (hit me two times in the last six months).

    You can find the ";" proposal in RFC 1866, section 8.2.1.

      It is easy to change the behaviour as noted above. I think it is wrong for similar reasons to you. If you have a look at the defaults for CGI::Simple you will see that many of the defaults are different.

      cheers

      tachyon

      The semicolon separator didn't work here. <META HTTP-EQUIV="Refresh" CONTENT="0;URL=http://www.free-cgi.com"> If the url is a script with multiple parameters, my server doesn't like semi-colon separators. Here, I had to go back to ampersands.
Re: Why does CGI::query_string make semicolons the rule, not the exception?
by blokhead (Monsignor) on Apr 13, 2004 at 14:22 UTC
    Update: Sorry.. Realized you weren't asking how to change the URL style emitted by query_string... You probably know how to do that. I'm not sure which browsers do support the semicolon style, and I can't remember ever seeing a site use it (probably due to your claim about MSIE not liking it). Anyway, nothing to see here folks..

    ...

    Check the docs! You can specify your preference like this: use CGI qw/param -oldstyle_urls/;

    -newstyle_urls
    Separate the name=value pairs in CGI parameter query strings with semicolons rather than ampersands. For example:

    ?name=fred;age=24;favorite_color=3

    Semicolon-delimited query strings are always accepted, but will not be emitted by self_url() and query_string() unless the -newstyle_urls pragma is specified.

    This became the default in version 2.64.

    -oldstyle_urls
    Separate the name=value pairs in CGI parameter query strings with ampersands rather than semicolons. This is no longer the default.

    blokhead

      I can't remember ever seeing a site use it

      Any site using XHTML and passes GET parameters in links has to use that form (assuming they want their XHTML to pass validation). Strict XHTML thinks '&' is always the start of an escape (like '&nbsp;'), so your choices are to either seperate with semi-colons or to use '&amp;' instead. Laziness dictates which one is used.

      ----
      : () { :|:& };:

      Note: All code is untested, unless otherwise stated