Skip Menu |

This queue is for tickets about the Cache-Memcached CPAN distribution.

Report information
The Basics
Id: 93094
Status: new
Priority: 0/
Queue: Cache-Memcached

People
Owner: Nobody in particular
Requestors: unrtst [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Important
Broken in: 1.30
Fixed in: (no value)



Subject: [PATCH] bugfix for deleting keys that contain utf8 values
The test t/06_utf8_key.t did not test all methods (ex. delete), and delete does not work with a utf8 value for the key in Cache::Memcached 1.30. I've attached a patch that updates the test (which is more-or-less a copy of 02_keys.t with changed keys), and corrects the delete() method (one line change).
Subject: Cache-Memcached-1.30.utf8-bugfix.patch
Only in Cache-Memcached-1.30.utf8-bugfix: 06_utf8_key.t diff -rup Cache-Memcached-1.30.orig/lib/Cache/Memcached.pm Cache-Memcached-1.30.utf8-bugfix/lib/Cache/Memcached.pm --- Cache-Memcached-1.30.orig/lib/Cache/Memcached.pm 2012-05-19 19:28:36.000000000 -0400 +++ Cache-Memcached-1.30.utf8-bugfix/lib/Cache/Memcached.pm 2014-02-17 14:41:00.000000000 -0500 @@ -459,6 +459,11 @@ sub delete { $self->{'stats'}->{"delete"}++; $key = ref $key ? $key->[1] : $key; $time = $time ? " $time" : ""; + + # key reconstituted from server won't have utf8 on, so turn it off on input + # scalar to allow hash lookup to succeed + Encode::_utf8_off($key) if Encode::is_utf8($key); + my $cmd = "delete $self->{namespace}$key$time\r\n"; my $res = _write_and_read($self, $sock, $cmd); diff -rup Cache-Memcached-1.30.orig/t/06_utf8_key.t Cache-Memcached-1.30.utf8-bugfix/t/06_utf8_key.t --- Cache-Memcached-1.30.orig/t/06_utf8_key.t 2012-05-18 19:25:27.000000000 -0400 +++ Cache-Memcached-1.30.utf8-bugfix/t/06_utf8_key.t 2014-02-17 14:39:54.000000000 -0500 @@ -9,7 +9,7 @@ my $testaddr = "127.0.0.1:11211"; my $msock = IO::Socket::INET->new(PeerAddr => $testaddr, Timeout => 3); if ($msock) { - plan tests => 2; + plan tests => 19; } else { plan skip_all => "No memcached instance running at $testaddr\n"; exit 0; @@ -17,10 +17,59 @@ if ($msock) { my $memd = Cache::Memcached->new({ servers => [ $testaddr ], + namespace => "Cache::Memcached::t/$$/" . (time() % 100) . "/", }); +my $memcached_version; + +eval { + require version; + die "version too old" unless $version::VERSION >= 0.77; + $memcached_version = + version->parse( + $memd->stats('misc')->{hosts}->{$testaddr}->{misc}->{version} + ); + diag("Server version: $memcached_version") if $memcached_version; +}; + + use utf8; -my $key = "Ïâ"; +my $key1 = "Ïâ"; +my $key2 = "Ïâb"; +my $key3 = "Ïâc"; + +ok($memd->set($key1, "val1"), "set key1 as val1"); + +is($memd->get($key1), "val1", "get key1 is val1"); +ok(! $memd->add($key1, "val-replace"), "add key1 properly failed"); +ok($memd->add($key2, "val2"), "add key2 as val2"); +is($memd->get($key2), "val2", "get key2 is val2"); + +ok($memd->replace($key2, "val-replace"), "replace key2 as val-replace"); +is($memd->get($key2), "val-replace", "get key2 is val-replace"); +ok(! $memd->replace("key-noexist", "bogus"), "replace key-noexist properly failed"); + +ok($memd->delete($key1), "delete key1"); +ok(! $memd->get($key1), "get key1 properly failed"); + +SKIP: { + skip "Could not parse server version; version.pm 0.77 required", 8 + unless $memcached_version; + skip "Only using prepend/append on memcached >= 1.2.4, you have $memcached_version", 8 + unless $memcached_version && $memcached_version >= v1.2.4; + + ok(! $memd->append("key-noexist$key1", "bogus"), "append key-noexist properly failed"); + ok(! $memd->prepend("key-noexist$key1", "bogus"), "prepend key-noexist properly failed"); + ok($memd->set($key3, "base"), "set key3 to base"); + ok($memd->append($key3, "-end"), "appended -end to key3"); + ok($memd->get($key3, "base-end"), "key3 is base-end"); + ok($memd->prepend($key3, "start-"), "prepended start- to key3"); + ok($memd->get($key3, "start-base-end"), "key3 is base-end"); + + # clean up after ourselves + ok($memd->delete($key3), "delete key3"); +} -ok($memd->set($key, "val1"), "set key1 as val1"); -is($memd->get($key), "val1", "get key1 is val1"); +# clean up after ourselves +#ok($memd->delete($key1), "delete key1"); # already deleted +ok($memd->delete($key2), "delete key2");