Skip Menu |
 

Preferred bug tracker

Please visit the preferred bug tracker to report your issue.

This queue is for tickets about the CGI CPAN distribution.

Report information
The Basics
Id: 43006
Status: rejected
Priority: 0/
Queue: CGI

People
Owner: MARKSTOS [...] cpan.org
Requestors: MARKSTOS [...] cpan.org
Cc:
AdminCc:

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



Subject: PATCH: make query_string generate consistent output for equivalent input
MIME-Version: 1.0
X-Mailer: MIME-tools 5.427 (Entity 5.427)
Content-Type: text/plain
Charset: utf8
Content-Disposition: inline
Content-Transfer-Encoding: binary
X-RT-Original-Encoding: utf-8
Content-Length: 1144
Download (untitled) / with headers
text/plain 1.1k
Given two equivalent sets of query input, it's useful to be able to do a quick comparison to see if they are the same. If the 'query_string()' method generated output in a consistent format, it would help with this. I believe doing so is as easy as sorting the names and values it uses, as this patch does: -- CGI.pm-old 2009-02-03 15:00:31.000000000 -0500 +++ CGI.pm-new 2009-02-03 15:00:32.000000000 -0500 @@ -2744,9 +2744,9 @@ sub query_string { my($self) = self_or_default(@_); my($param,$value,@pairs); - foreach $param ($self->param) { + foreach $param (sort $self->param) { my($eparam) = escape($param); - foreach $value ($self->param($param)) { + foreach $value (sort $self->param($param)) { $value = escape($value); next unless defined $value; push(@pairs,"$eparam=$value"); ###### Here's a simple test for the patch. It fails before the patch and passes afterwards: use Test::More 'no_plan'; use CGI; my $q1 = CGI->new('a=1;b=2'); my $q2 = CGI->new('b=2;a=1'); is($q1->query_string ,$q2->query_string , "query string format is reliable"); Mark
MIME-Version: 1.0
X-Mailer: MIME-tools 5.427 (Entity 5.427)
Content-Disposition: inline
Charset: utf8
Content-Type: text/plain
Message-ID: <rt-3.6.HEAD-14916-1249217815-363.43006-0-0 [...] rt.cpan.org>
Content-Transfer-Encoding: binary
X-RT-Original-Encoding: utf-8
Content-Length: 48
This patch has been applied in my git repo now.
MIME-Version: 1.0
Subject: PATCH: make query_string generate consistent output for equivalent input (rolling back)
X-Mailer: MIME-tools 5.427 (Entity 5.427)
Content-Disposition: inline
Charset: utf8
Content-Type: text/plain
Message-ID: <rt-3.6.HEAD-26882-1250164526-218.43006-0-0 [...] rt.cpan.org>
Content-Transfer-Encoding: binary
X-RT-Original-Encoding: utf-8
RT-Send-CC: lds [...] cpan.org
Content-Length: 1731
Download (untitled) / with headers
text/plain 1.6k
After further consideration, I'm going to be rolling back this patch, which is also in my git repo. The peer feedback is here. http://www.perlmonks.org/index.pl?node_id=788093 Lincoln, What's your opinion on sorted_query_string()? Does it seems interesting to include in the core, or would you rather have it supplied through a plugin? If I'm the only person who has asked for the feature in the last 12 years, a plugin seems like the way to go... Mark On Tue Feb 03 15:02:01 2009, MARKSTOS wrote: Show quoted text
> Given two equivalent sets of query input, it's useful to be able to do a > quick comparison to see if they are the same. If the 'query_string()' > method generated output in a consistent format, it would help with this. > > I believe doing so is as easy as sorting the names and values it uses, > as this patch does: > > -- CGI.pm-old 2009-02-03 15:00:31.000000000 -0500 > +++ CGI.pm-new 2009-02-03 15:00:32.000000000 -0500 > @@ -2744,9 +2744,9 @@ > sub query_string { > my($self) = self_or_default(@_); > my($param,$value,@pairs); > - foreach $param ($self->param) { > + foreach $param (sort $self->param) { > my($eparam) = escape($param); > - foreach $value ($self->param($param)) { > + foreach $value (sort $self->param($param)) { > $value = escape($value); > next unless defined $value; > push(@pairs,"$eparam=$value"); > > ###### > > Here's a simple test for the patch. It fails before the patch and passes > afterwards: > > use Test::More 'no_plan'; > use CGI; > > my $q1 = CGI->new('a=1;b=2'); > my $q2 = CGI->new('b=2;a=1'); > > is($q1->query_string > ,$q2->query_string > , "query string format is reliable"); > > Mark
MIME-Version: 1.0
X-Mailer: MIME-tools 5.427 (Entity 5.427)
Content-Disposition: inline
Charset: utf8
Content-Type: text/plain
Message-ID: <rt-3.6.HEAD-30017-1251053966-719.43006-0-0 [...] rt.cpan.org>
Content-Transfer-Encoding: binary
X-RT-Original-Encoding: utf-8
Content-Length: 198
Download (untitled) / with headers
text/plain 198b
I'll just note something related: Bugzilla sub-classes CGI and adds a method like this. They call it canonicalize_query. This method not only sorts, it allows you to exclude specific values as well.
MIME-Version: 1.0
X-Mailer: MIME-tools 5.427 (Entity 5.427)
Content-Disposition: inline
Content-Type: text/plain; charset="UTF-8"
Message-ID: <rt-3.8.HEAD-14822-1358905696-39.43006-0-0 [...] rt.cpan.org>
Content-Transfer-Encoding: binary
X-RT-Original-Encoding: utf-8
RT-Send-CC: lds [...] cpan.org
Content-Length: 100
Download (untitled) / with headers
text/plain 100b
I decided this should be a plugin, so I'm rejecting this proposal to add this feature to the core.


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.