Problem about Perl driver string utf8 encode.

100 views
Skip to first unread message

nightsailer

unread,
Dec 18, 2009, 9:47:36 AM12/18/09
to mongodb-dev
Hi,
I found a problem about perl driver:

test code:

my $t = $mongo_dbh->get_collection('test');
my $word = '测试';
$t->insert({ title => $word });

my $row = $t->find_one();
print "title:",$row->{title}, "\n";


the output is not expect, it will output some strange fuzzy string.

and, I use mongo shell to check, the title field stored incorrectly.
It seems "double" encode, I fix the test code:

my $t = $mongo_dbh->get_collection('test');
my $word = '测试';
$t->insert({ title => decode_utf8($word) });

my $row = $t->find_one();
print "title:",$row->{title}, "\n";

now, output is right. and mongo shell is also show ok.

I think maybe perl driver should auto decode string from utf8 or
perl's internal format
into a sequence of logical characters before store it to backend db?

I've test on mongo shell, it can handle Chinese string transparent, so
I think perl should do.
also PHP driver, it works fine.

Kristina Chodorow

unread,
Dec 18, 2009, 2:24:06 PM12/18/09
to mongo...@googlegroups.com
I've pushed a fix to Github (http://github.com/mongodb/mongo-perl-driver), or you can wait until Tuesday (which is when I'm planning on releasing version .27).

Sorry about that, I didn't realise the Perl function that it would double encode strings that already were UTF8.  Now it'll only encode it if it isn't valid UTF8 already.


2009/12/18 nightsailer <night...@gmail.com>

--

You received this message because you are subscribed to the Google Groups "mongodb-dev" group.
To post to this group, send email to mongo...@googlegroups.com.
To unsubscribe from this group, send email to mongodb-dev...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/mongodb-dev?hl=en.



nightsailer

unread,
Dec 19, 2009, 12:40:03 AM12/19/09
to mongodb-dev
I've pulled and test again, it works fine now.
Awesome work!

On Dec 19, 3:24 am, Kristina Chodorow <krist...@10gen.com> wrote:
> I've pushed a fix to Github (http://github.com/mongodb/mongo-perl-driver),
> or you can wait until Tuesday (which is when I'm planning on releasing
> version .27).
>
> Sorry about that, I didn't realise the Perl function that it would double
> encode strings that already were UTF8.  Now it'll only encode it if it isn't
> valid UTF8 already.
>

> 2009/12/18 nightsailer <nightsai...@gmail.com>

> > mongodb-dev...@googlegroups.com<mongodb-dev%2Bunsubscribe@googlegr oups.com>

Reply all
Reply to author
Forward
0 new messages