Thiemo Mättig (WMDE) has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/249423

Change subject: Regression: Allow spaces in MemcachedBagOStuff cache keys again
......................................................................

Regression: Allow spaces in MemcachedBagOStuff cache keys again

This fixes a regression introduced in If3e20c6. It brakes stuff in
Wikibase because we are using the version number constant as part
of a cache key prefix. Currently the Wikibase version is set to
"0.5 alpha".

We can also fix this by replacing the space in our constant with
"%20" or by applying an additional rawurlencode when constructing
the cache key. I will submit exactly that as an other patch in
Wikibase. I would still like to see this regression been fixed,
because:

* Space characters were allowed before.
* The character is still safe and encoded by the same rawurlencode
  as in the previous version.
* The comment already says "contains no control characters and no
  characters above the ASCII range". Which means space should be
  allowed since it is neither a control character nor above the
  ASCII range.

Change-Id: Ia2fd4ed6738a10e02050bced947ef5d4e8b98980
---
M includes/libs/objectcache/MemcachedBagOStuff.php
M tests/phpunit/includes/objectcache/MemcachedBagOStuffTest.php
2 files changed, 36 insertions(+), 1 deletion(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/23/249423/1

diff --git a/includes/libs/objectcache/MemcachedBagOStuff.php 
b/includes/libs/objectcache/MemcachedBagOStuff.php
index ef6b3c7..c713a57 100644
--- a/includes/libs/objectcache/MemcachedBagOStuff.php
+++ b/includes/libs/objectcache/MemcachedBagOStuff.php
@@ -146,7 +146,7 @@
         * @throws Exception
         */
        public function validateKeyEncoding( $key ) {
-               if ( preg_match( '/[^\x21-\x7e]+/', $key ) ) {
+               if ( preg_match( '/[^\x20-\x7e]+/', $key ) ) {
                        throw new Exception( "Key contains invalid characters: 
$key" );
                }
                return $key;
diff --git a/tests/phpunit/includes/objectcache/MemcachedBagOStuffTest.php 
b/tests/phpunit/includes/objectcache/MemcachedBagOStuffTest.php
index b0c9e4f..0b03c99 100644
--- a/tests/phpunit/includes/objectcache/MemcachedBagOStuffTest.php
+++ b/tests/phpunit/includes/objectcache/MemcachedBagOStuffTest.php
@@ -67,4 +67,39 @@
                        $this->cache->makeKey( 'long_key_part_hashed', 
str_repeat( 'y', 500 ) )
                );
        }
+
+       /**
+        * @dataProvider validKeyProvider
+        */
+       public function testValidateKeyEncoding( $key ) {
+               $this->assertSame( $key, $this->cache->validateKeyEncoding( 
$key ) );
+       }
+
+       public function validKeyProvider() {
+               return array(
+                       'empty' => array( '' ),
+                       'space' => array( ' ' ),
+                       'digits' => array( '09' ),
+                       'letters' => array( 'AZaz' ),
+                       'ASCII special characters' => array( 
'!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~' ),
+               );
+       }
+
+       /**
+        * @dataProvider invalidKeyProvider
+        */
+       public function testValidateKeyEncodingThrowsException( $key ) {
+               $this->setExpectedException( 'Exception' );
+               $this->cache->validateKeyEncoding( $key );
+       }
+
+       public function invalidKeyProvider() {
+               return array(
+                       array( "\x00" ),
+                       array( "\x1F" ),
+                       array( "\x7F" ),
+                       array( "\x80" ),
+                       array( "\xFF" ),
+               );
+       }
 }

-- 
To view, visit https://gerrit.wikimedia.org/r/249423
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ia2fd4ed6738a10e02050bced947ef5d4e8b98980
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Thiemo Mättig (WMDE) <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to