* @return string
*/
public function makeKeyInternal( $keyspace, $args ) {
- $key = $keyspace . ':' . implode( ':', $args );
+ $key = $keyspace;
+ foreach ( $args as $arg ) {
+ $arg = str_replace( ':', '%3A', $arg );
+ $key = $key . ':' . $arg;
+ }
return strtr( $key, ' ', '_' );
}
// the separator character needed for each argument.
$charsLeft = 255 - strlen( $keyspace ) - count( $args );
- $that = $this;
$args = array_map(
- function ( $arg ) use ( $that, &$charsLeft ) {
+ function ( $arg ) use ( &$charsLeft ) {
+ $arg = strtr( $arg, ' ', '_' );
+
// Make sure %, #, and non-ASCII chars are escaped
$arg = preg_replace_callback(
'/[^\x21-\x22\x24\x26-\x7e]+/',
);
if ( $charsLeft < 0 ) {
- $args = array( '##' . md5( implode( ':', $args ) ) );
+ return $keyspace . ':##' . md5( implode( ':', $args ) );
}
- return parent::makeKeyInternal( $keyspace, $args );
+ return $keyspace . ':' . implode( ':', $args );
}
/**
$globalKey,
'Local key and global key with same parameters should not be equal'
);
+
+ $this->assertNotEquals(
+ $cache->makeKeyInternal( 'prefix', array( 'a', 'bc:', 'de' ) ),
+ $cache->makeKeyInternal( 'prefix', array( 'a', 'bc', ':de' ) )
+ );
}
/**
$this->assertEquals(
$this->cache->makeKey( 'but spaces', 'hashes#', "and\nnewlines", 'are_not' ),
- 'test:but%20spaces:hashes%23:and%0Anewlines:are_not'
+ 'test:but_spaces:hashes%23:and%0Anewlines:are_not'
);
$this->assertEquals(
$this->assertEquals(
$this->cache->makeKey( 'this', 'key', 'contains', '𝕥𝕠𝕠 𝕞𝕒𝕟𝕪 𝕞𝕦𝕝𝕥𝕚𝕓𝕪𝕥𝕖 𝕔𝕙𝕒𝕣𝕒𝕔𝕥𝕖𝕣𝕤' ),
- 'test:this:key:contains:#60190c8f5a63ba5438b124f5c10b91d0'
+ 'test:this:key:contains:#c118f92685a635cb843039de50014c9c'
);
$this->assertEquals(