Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support ";\s*" separater and valuless keys #1

Closed
wants to merge 1 commit into from

Conversation

kazeburo
Copy link

Added suppoting ";" separator. W3C recommends that all web servers support ; separators in addition to & separators. This p-r also supports space after separator, like this RT.
https://rt.cpan.org/Public/Bug/Display.html?id=31055

And I added valueless keys support. When foo&bar=baz is given, foo parameter is not accessible. Plack::Request support this.

@chansen
Copy link
Owner

chansen commented Feb 1, 2014

Before going further we really need to define the application/www-form-urlencoded format. I propose that we implement the draft written by @hoehrmann. That way we would get consistent behavior between implementations.

I noticed that Plack recently changed it's decoder, plack/Plack#445.

@miyagawa and @yanik would you care to join the discussion so we can settle this for once?

#!/usr/bin/perl
use strict;
use warnings;

sub decode {
    my ($encoded) = @_;

    my @params;
    foreach my $pair (split /[&;]/, $encoded, -1) {
        my ($name, $value) = split /[=]/, $pair, 2;
        $name = '' unless defined $name;
        for ($name, $value) {
            next unless defined;
            y/+/\x20/;
            s/%([0-9a-fA-F]{2})/chr(hex($1))/ge;
        }
        push @params, $name, $value;
    }
    return \@params;
}

# Tests based on application/www-form-urlencoded draft written by B. Hoehrmann
# <http://tools.ietf.org/html/draft-hoehrmann-urlencoded-01>

my @tests = (
    [ 'a;b',                => [ 'a'    => undef, 'b'  => undef ] ],
    [ 'a ; b',              => [ 'a '   => undef, ' b' => undef ] ],
    [ 'a==1;b==2',          => [ 'a'    => '=1',  'b'  => '=2'  ] ],
    [ 'Fo%2=',              => [ 'Fo%2' => ''                   ] ],
    [ ' a = 1 '             => [ ' a '  => ' 1 '                ] ],
    [ '+a+=+1+'             => [ ' a '  => ' 1 '                ] ],
    [ '%20a%20=%201%20'     => [ ' a '  => ' 1 '                ] ],
    [ ';'                   => [ ''     => undef, ''   => undef ] ],
    [ ';='                  => [ ''     => undef, ''   => ''    ] ],
    [ '=;'                  => [ ''     => '',    ''   => undef ] ],
    [ '=;='                 => [ ''     => '',    ''   => ''    ] ],
    [ '=',                  => [ ''     => '',                  ] ],
    [ '',                   => [                                ] ],
);

use Test::More;
foreach my $test (@tests) {
    my ($string, $expected) = @$test;
    is_deeply(decode($string), $expected, qq["$string"]);
}

done_testing();

@kazeburo
Copy link
Author

kazeburo commented Feb 1, 2014

I found another document about application/x-www-form-urlencoded
http://www.w3.org/TR/html5/forms.html#url-encoded-form-data
ruby's uri module refers this
http://docs.ruby-lang.org/en/2.0.0/URI.html

@chansen
Copy link
Owner

chansen commented Feb 1, 2014

W3's definition of application/www-form-urlencoded is mostly useless as it focus on encoding of perfect data. I would like to bring on @kraih to this discussion, I'm sure he has some valuable POV's.

@chansen
Copy link
Owner

chansen commented Feb 7, 2014

Considering that the current implementation process millions of requests every day (POST and GET requests) and is mostly in agreement with W3 and IETF I'm going to reject this pull request.

@chansen
Copy link
Owner

chansen commented Feb 20, 2014

By popular demand, I have implemented support for ";" as a separator and added support for parameters without value (i.e. without '=' sign).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants