From: Timo Tijhof Date: Sat, 14 Sep 2019 02:04:26 +0000 (+0100) Subject: objectcache: Escape dots from cache keys in StatsD metrics X-Git-Tag: 1.34.0-rc.0~171^2 X-Git-Url: http://git.cyclocoop.org/%27%40script%40/ecrire/?a=commitdiff_plain;h=9244cdb977898c0439e742dca58525b75004102d;p=lhc%2Fweb%2Fwiklou.git objectcache: Escape dots from cache keys in StatsD metrics Bug: T232907 Change-Id: Ia61256e24fe35803e69a83a1ca235e18297c75cd --- 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' ] ]; }