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