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

Encode content before calling LWP #27

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion lib/WebService/Solr.pm
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ sub generic_solr_request {
$self->agent->post(
$self->_gen_url( $path ),
Content_Type => 'application/x-www-form-urlencoded; charset=utf-8',
Content => { $self->default_params, %$params } ) ) );
Content => $self->_encode_content( { $self->default_params, %$params } ) ) ) );
}

sub _gen_url {
Expand All @@ -172,6 +172,18 @@ sub _gen_url {
return $url;
}

sub _encode_content {
my ( $self, $param ) = @_;

if ( ref $param eq "HASH" ) {
return { map { $self->_encode_content($_) } %$param };
} elsif ( ref $param eq "ARRAY" ) {
return [ map { $self->_encode_content($_) } @$param ];
} else {
return encode('utf-8', $param);
}
}

sub _send_update {
my ( $self, $xml, $params, $autocommit ) = @_;
$autocommit = $self->autocommit unless defined $autocommit;
Expand Down
11 changes: 10 additions & 1 deletion t/request/search.t
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use strict;
use warnings;

use Test::More tests => 5;
use Test::More tests => 8;
use Test::Mock::LWP;

use WebService::Solr;
Expand All @@ -28,6 +28,15 @@ my ( $expect_path, $expect_params );
is $solr->last_response, undef, "The last_response attribute hasn't been set yet";
$solr->search( 'foo' );
isa_ok $solr->last_response, 'WebService::Solr::Response';

$expect_params = {
q => "\xc3\x86\xc3\x98\xc3\x85",
wt => 'json',
fl => 'id',
fq => [ 'id:[0 TO 42]', "value:\xc3\x86\xc3\x98\xc3\x85" ]
};
$solr->search( "\xc6\xd8\xc5", { fl => 'id', fq => [ 'id:[0 TO 42]', "value:\xc6\xd8\xc5" ] } );
isa_ok $solr->last_response, 'WebService::Solr::Response';
}

sub _test_req {
Expand Down