From 91f5a7cc6bb546cb019eacc6348b0b3863851a64 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Sun, 26 Jun 2022 05:56:13 -0400 Subject: [PATCH] Convert potential spaces in Memcache(d) key names - Address https://github.com/friendica/friendica/issues/11630#issuecomment-1166475036 - Add test for space in cache keys --- src/Core/Cache/Type/MemcacheCache.php | 11 +++++++++++ src/Core/Cache/Type/MemcachedCache.php | 11 +++++++++++ src/Protocol/OStatus.php | 2 +- tests/src/Core/Cache/CacheTest.php | 9 +++++++++ 4 files changed, 32 insertions(+), 1 deletion(-) diff --git a/src/Core/Cache/Type/MemcacheCache.php b/src/Core/Cache/Type/MemcacheCache.php index 441c64c3a..225c33891 100644 --- a/src/Core/Cache/Type/MemcacheCache.php +++ b/src/Core/Cache/Type/MemcacheCache.php @@ -68,6 +68,17 @@ class MemcacheCache extends AbstractCache implements ICanCacheInMemory } } + /** + * Memcache doesn't allow spaces in keys + * + * @param string $key + * @return string + */ + protected function getCacheKey(string $key): string + { + return str_replace(' ', '_', parent::getCacheKey($key)); + } + /** * (@inheritdoc) */ diff --git a/src/Core/Cache/Type/MemcachedCache.php b/src/Core/Cache/Type/MemcachedCache.php index d86906de7..2d8b4e1c2 100644 --- a/src/Core/Cache/Type/MemcachedCache.php +++ b/src/Core/Cache/Type/MemcachedCache.php @@ -93,6 +93,17 @@ class MemcachedCache extends AbstractCache implements ICanCacheInMemory } } + /** + * Memcached doesn't allow spaces in keys + * + * @param string $key + * @return string + */ + protected function getCacheKey(string $key): string + { + return str_replace(' ', '_', parent::getCacheKey($key)); + } + /** * (@inheritdoc) */ diff --git a/src/Protocol/OStatus.php b/src/Protocol/OStatus.php index 90e52d673..36dbb06c8 100644 --- a/src/Protocol/OStatus.php +++ b/src/Protocol/OStatus.php @@ -2017,7 +2017,7 @@ class OStatus * cache or it is empty * * @param string $owner_nick Nickname of the feed owner - * @param string $last_update Date of the last update + * @param string $last_update Date of the last update (in "Y-m-d H:i:s" format) * @param integer $max_items Number of maximum items to fetch * @param string $filter Feed items filter (activity, posts or comments) * @param boolean $nocache Wether to bypass caching diff --git a/tests/src/Core/Cache/CacheTest.php b/tests/src/Core/Cache/CacheTest.php index 88154c9d2..c249aefbf 100644 --- a/tests/src/Core/Cache/CacheTest.php +++ b/tests/src/Core/Cache/CacheTest.php @@ -237,4 +237,13 @@ abstract class CacheTest extends MockedTest self::assertNotContains('value1', $list); self::assertNotContains('value2', $list); } + + /** + * @small + */ + public function testSpaceInKey() + { + self::assertTrue($this->instance->set('key space', 'value')); + self::assertEquals('value', $this->instance->get('key space')); + } }