[OpenSRF-GIT] OpenSRF branch rel_2_1 updated. osrf_rel_2_1_0-rc1-15-g4fe1fdc

Evergreen Git git at git.evergreen-ils.org
Mon May 21 17:20:03 EDT 2012


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "OpenSRF".

The branch, rel_2_1 has been updated
       via  4fe1fdc7d4561e04212444786fd61d95eae69eb0 (commit)
       via  3e97b0f69be04957eefa149d06e05111f3ad4291 (commit)
      from  c6cf4d9b6530f5b8b6bdf95c26db9986656fcce8 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 4fe1fdc7d4561e04212444786fd61d95eae69eb0
Author: Galen Charlton <gmc at esilibrary.com>
Date:   Mon May 21 17:02:34 2012 -0400

    LP# 953299 - defend against null and zero-length cache keys
    
    Ignore undefined and zero-length (after key normalization) cache
    keys.
    
    Signed-off-by: Galen Charlton <gmc at esilibrary.com>
    Signed-off-by: Dan Scott <dan at coffeecode.net>

diff --git a/src/perl/lib/OpenSRF/Utils/Cache.pm b/src/perl/lib/OpenSRF/Utils/Cache.pm
index 53cf966..ba9f1a1 100644
--- a/src/perl/lib/OpenSRF/Utils/Cache.pm
+++ b/src/perl/lib/OpenSRF/Utils/Cache.pm
@@ -110,9 +110,11 @@ sub new {
 sub put_cache {
 	my($self, $key, $value, $expiretime ) = @_;
 
+	return undef unless( defined $key and defined $value );
+
 	$key = _clean_cache_key($key);
 
-	return undef unless( defined $key and defined $value );
+	return undef if( $key eq '' ); # no zero-length keys
 
 	$value = OpenSRF::Utils::JSON->perl2JSON($value);
 
@@ -158,8 +160,9 @@ sub put_cache {
 
 sub delete_cache {
 	my( $self, $key ) = @_;
+	return undef unless defined $key;
 	$key = _clean_cache_key($key);
-	if(!$key) { return undef; }
+	return undef if $key eq ''; # no zero-length keys
 	if($self->{persist}){ _load_methods(); }
 	$self->{memcache}->delete($key);
 	if( $self->{persist} ) {
@@ -176,8 +179,12 @@ sub delete_cache {
 sub get_cache {
 	my($self, $key ) = @_;
 
+	return undef unless defined $key;
+
 	$key = _clean_cache_key($key);
 
+	return undef if $key eq ''; # no zero-length keys
+
 	my $val = $self->{memcache}->get( $key );
 	return OpenSRF::Utils::JSON->JSON2perl($val) if defined($val);
 

commit 3e97b0f69be04957eefa149d06e05111f3ad4291
Author: Dan Scott <dan at coffeecode.net>
Date:   Mon May 21 12:18:41 2012 -0400

    LP# 953299 - Prevent get/set of invalid cache keys
    
    Clients of OpenSRF::Utils::Cache occasionally request cache keys that
    contain invalid characters (a particular case is ISBNs that contain
    spaces), so strip those out of incoming get/set requests to avoid ugly
    memcached errors.
    
    Signed-off-by: Dan Scott <dan at coffeecode.net>
    Signed-off-by: Galen Charlton <gmc at esilibrary.com>

diff --git a/src/perl/lib/OpenSRF/Utils/Cache.pm b/src/perl/lib/OpenSRF/Utils/Cache.pm
index 1fb56a4..53cf966 100644
--- a/src/perl/lib/OpenSRF/Utils/Cache.pm
+++ b/src/perl/lib/OpenSRF/Utils/Cache.pm
@@ -109,6 +109,9 @@ sub new {
 
 sub put_cache {
 	my($self, $key, $value, $expiretime ) = @_;
+
+	$key = _clean_cache_key($key);
+
 	return undef unless( defined $key and defined $value );
 
 	$value = OpenSRF::Utils::JSON->perl2JSON($value);
@@ -155,6 +158,7 @@ sub put_cache {
 
 sub delete_cache {
 	my( $self, $key ) = @_;
+	$key = _clean_cache_key($key);
 	if(!$key) { return undef; }
 	if($self->{persist}){ _load_methods(); }
 	$self->{memcache}->delete($key);
@@ -172,6 +176,8 @@ sub delete_cache {
 sub get_cache {
 	my($self, $key ) = @_;
 
+	$key = _clean_cache_key($key);
+
 	my $val = $self->{memcache}->get( $key );
 	return OpenSRF::Utils::JSON->JSON2perl($val) if defined($val);
 
@@ -248,10 +254,29 @@ sub _load_methods {
 }
 
 
+=head2 _clean_cache_key
 
+Try to make the requested cache key conform to memcached's requirements. Per
+https://github.com/memcached/memcached/blob/master/doc/protocol.txt:
 
+"""
+Data stored by memcached is identified with the help of a key. A key
+is a text string which should uniquely identify the data for clients
+that are interested in storing and retrieving it.  Currently the
+length limit of a key is set at 250 characters (of course, normally
+clients wouldn't need to use such long keys); the key must not include
+control characters or whitespace.
+"""
 
+=cut
 
+sub _clean_cache_key {
+    my $key = shift;
+
+    $key =~ s{(\p{Cntrl}|\s)}{}g;
+
+    return $key;
+}
 
 1;
 
diff --git a/src/perl/t/09-Utils-Cache.t b/src/perl/t/09-Utils-Cache.t
index 8d4c85b..07941b7 100644
--- a/src/perl/t/09-Utils-Cache.t
+++ b/src/perl/t/09-Utils-Cache.t
@@ -1,7 +1,9 @@
 #!perl -T
 
-use Test::More tests => 1;
+use Test::More tests => 2;
 
 BEGIN {
 	use_ok( 'OpenSRF::Utils::Cache' );
 }
+
+is (OpenSRF::Utils::Cache::_clean_cache_key('ac.jacket.large.9780415590211 (hbk.)'), 'ac.jacket.large.9780415590211(hbk.)');

-----------------------------------------------------------------------

Summary of changes:
 src/perl/lib/OpenSRF/Utils/Cache.pm |   34 +++++++++++++++++++++++++++++++++-
 src/perl/t/09-Utils-Cache.t         |    4 +++-
 2 files changed, 36 insertions(+), 2 deletions(-)


hooks/post-receive
-- 
OpenSRF


More information about the opensrf-commits mailing list