diff options
-rw-r--r-- | core/MAINTAINERS.txt | 3 | ||||
-rw-r--r-- | core/lib/Drupal/Core/Config/DatabaseStorage.php | 2 | ||||
-rw-r--r-- | core/modules/locale/src/LocaleTranslation.php | 13 | ||||
-rw-r--r-- | core/modules/locale/tests/src/Kernel/LocaleTranslationTest.php | 18 |
4 files changed, 32 insertions, 4 deletions
diff --git a/core/MAINTAINERS.txt b/core/MAINTAINERS.txt index 0ef1dde096fe..075ea1b1e4ae 100644 --- a/core/MAINTAINERS.txt +++ b/core/MAINTAINERS.txt @@ -338,7 +338,7 @@ Page Cache - Fabian Franz 'Fabianx' https://www.drupal.org/u/fabianx Path -- Nathaniel Catchpole 'catch' https://www.drupal.org/u/catch +- ? Path Alias - Nathaniel Catchpole 'catch' https://www.drupal.org/u/catch @@ -402,7 +402,6 @@ System (module) Taxonomy - Jess Myrbo 'xjm' https://www.drupal.org/u/xjm -- Nathaniel Catchpole 'catch' https://www.drupal.org/u/catch Telephone - Stephen Mustgrave 'smustgrave' https://www.drupal.org/u/smustgrave diff --git a/core/lib/Drupal/Core/Config/DatabaseStorage.php b/core/lib/Drupal/Core/Config/DatabaseStorage.php index 60da9de12470..299693f2c779 100644 --- a/core/lib/Drupal/Core/Config/DatabaseStorage.php +++ b/core/lib/Drupal/Core/Config/DatabaseStorage.php @@ -272,7 +272,7 @@ class DatabaseStorage implements StorageInterface { * be unserialized. */ public function decode($raw) { - $data = @unserialize($raw); + $data = @unserialize($raw, ['allowed_classes' => FALSE]); return is_array($data) ? $data : FALSE; } diff --git a/core/modules/locale/src/LocaleTranslation.php b/core/modules/locale/src/LocaleTranslation.php index a9ccc93626f0..99e852650ee6 100644 --- a/core/modules/locale/src/LocaleTranslation.php +++ b/core/modules/locale/src/LocaleTranslation.php @@ -20,7 +20,9 @@ use Symfony\Component\HttpFoundation\RequestStack; */ class LocaleTranslation implements TranslatorInterface, DestructableInterface { - use DependencySerializationTrait; + use DependencySerializationTrait { + __sleep as traitSleep; + } /** * Storage for strings. @@ -161,4 +163,13 @@ class LocaleTranslation implements TranslatorInterface, DestructableInterface { } } + /** + * {@inheritdoc} + */ + public function __sleep(): array { + // ::$translations is an array of LocaleLookup objects, which have the + // database service injected and therefore cannot be serialized safely. + return array_diff($this->traitSleep(), ['translations']); + } + } diff --git a/core/modules/locale/tests/src/Kernel/LocaleTranslationTest.php b/core/modules/locale/tests/src/Kernel/LocaleTranslationTest.php index 316384330f8b..b52d29348253 100644 --- a/core/modules/locale/tests/src/Kernel/LocaleTranslationTest.php +++ b/core/modules/locale/tests/src/Kernel/LocaleTranslationTest.php @@ -21,11 +21,29 @@ class LocaleTranslationTest extends KernelTestBase { ]; /** + * {@inheritdoc} + */ + protected function setUp(): void { + parent::setUp(); + + $this->installSchema('locale', [ + 'locales_location', + 'locales_source', + 'locales_target', + ]); + } + + /** * Tests that \Drupal\locale\LocaleTranslation is serializable. */ public function testSerializable(): void { + /** @var \Drupal\locale\LocaleTranslation $translation */ $translation = $this->container->get('string_translator.locale.lookup'); $this->assertInstanceOf(LocaleTranslation::class, $translation); + // Ensure that the \Drupal\locale\LocaleTranslation::$translations property + // has some cached translations in it. Without this, serialization will not + // actually be tested fully. + $translation->getStringTranslation('es', 'test', ''); // Prove that serialization and deserialization works without errors. $this->assertNotNull($translation); |