Subject: | Business::Maxmind chokes if any UTF-8 chars are present in the data. |
Date: | Tue, 01 Sep 2009 16:40:04 -0500 |
To: | tjmather [...] maxmind.com, bug-Business-MaxMind [...] rt.cpan.org |
From: | Michael Schout <mschout [...] gkg.net> |
Hi!
I've discovered a problem with
Business::MaxMind::CreditCardFraudDetection and UTF-8 data:
If any of the fields passed to CreditCardFraudDetection contain chars
above ASCII value 255, the query blows up with error like the following:
Can't escape \x{015B}, try uri_escape_utf8() instead at
/home/mschout/dev/maxmind/blib/lib/Business/MaxMind/HTTPBase.pm line 156
Attached is a patch against 1.50 that fixes this in the manner suggested
by the error message. In addition, I have included a test case
(t/utf8.t), and also I added URI 1.36 to PREREQ_PM, because that is when
uri_escape_utf8() was first exported by default by URI.
If you have any questions, let me know.
Thanks.
Michael Schout
diff --git a/Makefile.PL b/Makefile.PL
index e92242d..21b46e3 100644
--- a/Makefile.PL
+++ b/Makefile.PL
@@ -5,7 +5,10 @@ use ExtUtils::MakeMaker;
WriteMakefile(
'NAME' => 'Business::MaxMind',
'VERSION_FROM' => 'lib/Business/MaxMind/HTTPBase.pm', # finds $VERSION
- 'PREREQ_PM' => { LWP::UserAgent => 0 }, # e.g., Module::Name => 1.1
+ 'PREREQ_PM' => {
+ LWP::UserAgent => 0,
+ URI => 1.36
+ }, # e.g., Module::Name => 1.1
($] >= 5.005 ? ## Add these new keywords supported since 5.005
(ABSTRACT => 'Business::MaxMind - Access MaxMind minFraud, Telephone and Location verification services', # retrieve abstract from module
AUTHOR => 'TJ Mather <tjmather@maxmind.com>') : ()),
diff --git a/lib/Business/MaxMind/HTTPBase.pm b/lib/Business/MaxMind/HTTPBase.pm
index 5f797e6..e01b96b 100644
--- a/lib/Business/MaxMind/HTTPBase.pm
+++ b/lib/Business/MaxMind/HTTPBase.pm
@@ -153,7 +153,7 @@ sub querySingleServer {
$self->{url};
my $check_field = $self->{check_field};
my $queries = $self->{queries};
- my $query_string = join('&', map { "$_=" . uri_escape($queries->{$_}) } keys %$queries);
+ my $query_string = join('&', map { "$_=" . uri_escape_utf8($queries->{$_}) } keys %$queries);
$query_string .= "&clientAPI=$API_VERSION";
if ($self->{"timeout"} > 0) {
$self->{ua}->timeout($self->{"timeout"});
diff --git a/t/utf8.t b/t/utf8.t
new file mode 100644
index 0000000..abfcf27
--- /dev/null
+++ b/t/utf8.t
@@ -0,0 +1,31 @@
+#!/usr/bin/env perl
+
+use strict;
+use utf8;
+use Test::More tests => 3;
+use Test::Exception;
+
+use_ok 'Business::MaxMind::CreditCardFraudDetection';
+
+my $ccfs = Business::MaxMind::CreditCardFraudDetection->new(
+ isSecure => 1, debug => 1);
+
+isa_ok $ccfs, 'Business::MaxMind::CreditCardFraudDetection';
+
+$ccfs->input(
+ i => '24.24.24.24',
+ domain => 'yahoo.com',
+ city => 'OÅwiÄcim',
+ region => 'MaÅopolskie',
+ postal => '32-600',
+ country => 'PL',
+ bin => '549099');
+
+eval {
+ $ccfs->query;
+ pass("query with UTF-8");
+};
+if ($@) {
+ fail("query with UTF-8");
+ diag($@);
+}