From 9244cdb977898c0439e742dca58525b75004102d Mon Sep 17 00:00:00 2001 From: Timo Tijhof Date: Sat, 14 Sep 2019 03:04:26 +0100 Subject: [PATCH] objectcache: Escape dots from cache keys in StatsD metrics Bug: T232907 Change-Id: Ia61256e24fe35803e69a83a1ca235e18297c75cd --- includes/libs/objectcache/wancache/WANObjectCache.php | 5 +++-- .../phpunit/includes/libs/objectcache/WANObjectCacheTest.php | 2 ++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/includes/libs/objectcache/wancache/WANObjectCache.php b/includes/libs/objectcache/wancache/WANObjectCache.php index 629d2cdcaf..70f35532d2 100644 --- a/includes/libs/objectcache/wancache/WANObjectCache.php +++ b/includes/libs/objectcache/wancache/WANObjectCache.php @@ -2488,8 +2488,9 @@ class WANObjectCache implements IExpiringStore, IStoreKeyEncoder, LoggerAwareInt */ private function determineKeyClassForStats( $key ) { $parts = explode( ':', $key, 3 ); - - return $parts[1] ?? $parts[0]; // sanity + // Sanity fallback in case the key was not made by makeKey. + // Replace dots because they are special in StatsD (T232907) + return strtr( $parts[1] ?? $parts[0], '.', '_' ); } /** diff --git a/tests/phpunit/includes/libs/objectcache/WANObjectCacheTest.php b/tests/phpunit/includes/libs/objectcache/WANObjectCacheTest.php index ac988e6467..076bf5229d 100644 --- a/tests/phpunit/includes/libs/objectcache/WANObjectCacheTest.php +++ b/tests/phpunit/includes/libs/objectcache/WANObjectCacheTest.php @@ -1981,6 +1981,8 @@ class WANObjectCacheTest extends PHPUnit\Framework\TestCase { [ 'domain:page:5', 'page' ], [ 'domain:main-key', 'main-key' ], [ 'domain:page:history', 'page' ], + // Regression test for T232907 + [ 'domain:foo-bar-1.2:abc:v2', 'foo-bar-1_2' ], [ 'missingdomainkey', 'missingdomainkey' ] ]; } -- 2.20.1