Skip Menu |

This queue is for tickets about the URI CPAN distribution.

Report information
The Basics
Id: 27
Status: resolved
Worked: 15 min
Priority: 0/
Queue: URI

People
Owner: GAAS [...] cpan.org
Requestors: siracusa [...] mindspring.com
Cc:
AdminCc:

Bug Information
Severity: Wishlist
Broken in: (no value)
Fixed in: (no value)



Subject: Query separator is hard-coded to be '&'
Query parameters must be separated with '&' Example: http://foo.com/goo?a=1&b=2&c=3 I'd like other separators to be supported and/or specified per-URI. Example: http://foo.com/goo?a=1;b=2;c=3
To: bug-URI [...] rt.cpan.org
Subject: Re: [cpan #27] Query separator is hard-coded to be '&'
From: Gisle Aas <gisle [...] ActiveState.com>
Date: 08 Nov 2001 19:37:38 -0800
Looks like a good idea!
[gisle@ActiveState.com - Thu Nov 8 22:37:49 2001]: Show quoted text
> Looks like a good idea! >
I've implemented something similar on my own to split query strings on "&" or ";". Attached is a quick patch for URI-1.17/URI/_query.pm, which changes the split regex on line 48 to /[&;]/ rather than just /&/. Hope that's helpful. (darren)
--- _query.pm.orig Wed Dec 12 12:04:34 2001 +++ _query.pm Wed Dec 12 12:04:43 2001 @@ -45,7 +45,7 @@ return if !defined($old) || !length($old) || !defined(wantarray); return unless $old =~ /=/; # not a form map { s/\+/ /g; uri_unescape($_) } - map { /=/ ? split(/=/, $_, 2) : ($_ => '')} split(/&/, $old); + map { /=/ ? split(/=/, $_, 2) : ($_ => '')} split(/[&;]/, $old); } # Handle ...?dog+bones type of query
From: trevor.schellhorn-perl [...] marketingtips.com
[DARREN - Wed Dec 12 12:09:22 2001]: Show quoted text
> [gisle@ActiveState.com - Thu Nov 8 22:37:49 2001]: >
> > Looks like a good idea! > >
> > I've implemented something similar on my own to split query strings on > "&" or ";". Attached is a quick patch for URI-1.17/URI/_query.pm, > which > changes the split regex on line 48 to /[&;]/ rather than just /&/. > > Hope that's helpful. > > (darren)
When is this going to be implemented into the module?
From: srezic [...] cpan.org
[guest - Mon Oct 27 20:22:39 2003]: Show quoted text
> [DARREN - Wed Dec 12 12:09:22 2001]: >
> > [gisle@ActiveState.com - Thu Nov 8 22:37:49 2001]: > >
> > > Looks like a good idea! > > >
> > > > I've implemented something similar on my own to split query strings on > > "&" or ";". Attached is a quick patch for URI-1.17/URI/_query.pm, > > which > > changes the split regex on line 48 to /[&;]/ rather than just /&/. > > > > Hope that's helpful. > > > > (darren)
> > When is this going to be implemented into the module?
I want just add that the current behavior means that URI.pm and CGI.pm are not interoperable. Example: $ perl -MCGI -MURI -e 'my $uri = URI->new; $uri->query(CGI->new({a=>1,b=>2})->query_string); warn join "|", $uri->query_form' a|1;b=2 at -e line 1. One has to set "oldstyle_urls" to force using "&" as a separator: $ perl -MCGI=:oldstyle_urls -MURI -e 'my $uri = URI->new; $uri->query(CGI->new({a=>1,b=>2})->query_string); warn join "|", $uri->query_form' a|1|b|2 at -e line 1. Regards, Slaven
I'd love to see this implemented. My use case is I've found that IE doesn't like URLs with semicolons in meta refresh tags. So I have a method which takes a URL and translates the query string from using semicolons to ampersand separators. Because of this bug I can't use URI for this and have to instead do it by hand. $ perl -wle 'use URI; $u = URI->new(shift); print $u->query' http://foo.com?foo=bar;baz=biff foo=bar
[gisle@ActiveState.com - Thu Nov 8 22:37:49 2001]: Show quoted text
> Looks like a good idea!
And it is. Has been for 4 years, but the ticket is still open. Is it ever going to be addressed? Is there any issue that has caused this to stall for so long? The relevant W3C recommendation dates back to 1997; it’s somewhat embarrassing that this still isn’t supported. Unlike Michael, I want to *generate* URIs with semicolons. URI::Query has this functionality, but I’d rather stick with URI itself – if I can! Currently, I instead bastardise CGI.pm as a URI generator, playing various kinds of tricks on it, but that is anything but satisfactory. Can I do something to help the along? If I supply a patch to add support along with a full set of tests for this, will that speed up things?
The attached is a rather hackish method of overriding this behavoir in query_form; most likely the seperator should be made a variable which can be overridden or localized at will.
package Debbugs::URI; =head1 NAME Debbugs::URI -- Derivative of URI which overrides the query_param method to use ';' instead of '&' for separators. =head1 SYNOPSIS use Debbugs::URI; =head1 DESCRIPTION See L<URI> for more information. =head1 BUGS None known. =cut use warnings; use strict; use base qw(URI URI::_query); =head2 query_param $uri->query_form( $key1 => $val1, $key2 => $val2, ... ) Exactly like query_param in L<URI> except query elements are joined by ; instead of &. =cut { package URI::_query; no warnings 'redefine'; # Handle ...?foo=bar&bar=foo type of query sub URI::_query::query_form { my $self = shift; my $old = $self->query; if (@_) { # Try to set query string my @new = @_; if (@new == 1) { my $n = $new[0]; if (ref($n) eq "ARRAY") { @new = @$n; } elsif (ref($n) eq "HASH") { @new = %$n; } } my @query; while (my($key,$vals) = splice(@new, 0, 2)) { $key = '' unless defined $key; $key =~ s/([;\/?:@&=+,\$\[\]%])/$URI::Escape::escapes{$1}/g; $key =~ s/ /+/g; $vals = [ref($vals) eq "ARRAY" ? @$vals : $vals]; for my $val (@$vals) { $val = '' unless defined $val; $val =~ s/([;\/?:@&=+,\$\[\]%])/$URI::Escape::escapes{$1}/g; $val =~ s/ /+/g; push(@query, "$key=$val"); } } # This is the only line we have changed $self->query(@query ? join(';', @query) : undef); } return if !defined($old) || !length($old) || !defined(wantarray); return unless $old =~ /=/; # not a form map { s/\+/ /g; uri_unescape($_) } map { /=/ ? split(/=/, $_, 2) : ($_ => '')} split(/&/, $old); } } 1; __END__
$u->query_form support for ";" was implemented in URI-1.37