From ac6a9be2ebe7ac48c2756904f46961c844a0da01 Mon Sep 17 00:00:00 2001 From: Maxence Lange Date: Thu, 6 Nov 2025 20:28:33 -0100 Subject: [PATCH] fix(lexicon): enforce type from lexicon Signed-off-by: Maxence Lange --- apps/dav/lib/ConfigLexicon.php | 1 + lib/private/AppConfig.php | 12 +++++++++--- lib/public/Config/Lexicon/Entry.php | 3 ++- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/apps/dav/lib/ConfigLexicon.php b/apps/dav/lib/ConfigLexicon.php index 921c6f2036b..8aa6e18fee1 100644 --- a/apps/dav/lib/ConfigLexicon.php +++ b/apps/dav/lib/ConfigLexicon.php @@ -35,6 +35,7 @@ class ConfigLexicon implements ILexicon { defaultRaw: true, definition: 'Whether to not expose the system address book to users', lazy: true, + options: Entry::ENFORCE_VALUE_TYPE ), ]; } diff --git a/lib/private/AppConfig.php b/lib/private/AppConfig.php index a9aa48a6c21..7e719a2e462 100644 --- a/lib/private/AppConfig.php +++ b/lib/private/AppConfig.php @@ -478,7 +478,9 @@ class AppConfig implements IAppConfig { ): string { $this->assertParams($app, $key, valueType: $type); $origKey = $key; - $matched = $this->matchAndApplyLexiconDefinition($app, $key, $lazy, $type, $default); + /** @var ?Entry $lexiconEntry */ + $lexiconEntry = null; + $matched = $this->matchAndApplyLexiconDefinition($app, $key, $lazy, $type, $default, $lexiconEntry); if ($default === null) { // there is no logical reason for it to be null throw new \Exception('default cannot be null'); @@ -501,8 +503,12 @@ class AppConfig implements IAppConfig { && $knownType > 0 && !$this->isTyped(self::VALUE_MIXED, $knownType) && !$this->isTyped($type, $knownType)) { - $this->logger->warning('conflict with value type from database', ['app' => $app, 'key' => $key, 'type' => $type, 'knownType' => $knownType]); - throw new AppConfigTypeConflictException('conflict with value type from database'); + if ($lexiconEntry?->hasOption(Entry::ENFORCE_VALUE_TYPE)) { + $this->updateType($app, $key, $lexiconEntry->getValueType()->toAppConfigFlag()); + } else { + $this->logger->warning('conflict with value type from database', ['app' => $app, 'key' => $key, 'type' => $type, 'knownType' => $knownType]); + throw new AppConfigTypeConflictException('conflict with value type from database'); + } } /** diff --git a/lib/public/Config/Lexicon/Entry.php b/lib/public/Config/Lexicon/Entry.php index aa35730c4f1..220e8a7a383 100644 --- a/lib/public/Config/Lexicon/Entry.php +++ b/lib/public/Config/Lexicon/Entry.php @@ -21,7 +21,8 @@ use OCP\Config\ValueType; class Entry { /** @since 32.0.0 */ public const RENAME_INVERT_BOOLEAN = 1; - + /** @since 32.0.0 */ + public const ENFORCE_VALUE_TYPE = 2; private ?string $default = null; /**