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
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
This patch has been applied in my git repo now.
Subject: PATCH: make query_string generate consistent output for equivalent input (rolling back)
RT-Send-CC: lds [...] cpan.org
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
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.
RT-Send-CC: lds [...] cpan.org
I decided this should be a plugin, so I'm rejecting this proposal to add this feature to the core.