Skip to content

don't re-order multiple values for the same key with post_form #125

@neilb

Description

@neilb

I'm using an API that can take multiple strings, and returns a result for each string, in the same order as the strings were provided.

Initially I was doing this:

my $form_data = { 'q[]' => \@strings };
my $response  = $ua->post_form($url, $form_data, $headers);

But I found that depending on the strings, I wasn't getting the responses back in the expected order.

I just realised that the strings are being sorted, because of this line in www_form_urlencode():

return join("&", (ref $data eq 'ARRAY') ? (@terms) : (sort @terms) );

So for my case, I can fix it by doing this:

my $form_data = [ 'q[]' => \@strings ];

But I think that for the law of least surprise, I think a better behaviour would be to sort on the keys, but within a key to preserve the order.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions