diff --git a/src/Integrations/Divi/Design/DiviThemeOptionsUpdateAbility.php b/src/Integrations/Divi/Design/DiviThemeOptionsUpdateAbility.php index ffebb23..21518c2 100644 --- a/src/Integrations/Divi/Design/DiviThemeOptionsUpdateAbility.php +++ b/src/Integrations/Divi/Design/DiviThemeOptionsUpdateAbility.php @@ -170,17 +170,17 @@ final class DiviThemeOptionsUpdateAbility implements Ability, RequiresDiviFeatur return null; } $problem = ThemeOptionSpec::check($key, $value); + $normalized = $problem === null ? ThemeOptionSpec::normalize($key, $value) : null; if ($problem === null && ThemeOptionSpec::definition($key)['type'] === 'font') { - // Before Divi's sanitizer: it would only answer false, without suggestions. - $problem = FontCheck::problem($this->fonts, (string) $value); + // Before Divi's sanitizer: it would only answer false, without suggestions. The trimmed name is checked. + $problem = FontCheck::problem($this->fonts, (string) $normalized); } - if ($problem !== null) { - $errors[$field] = $problem; + if ($problem !== null || $normalized === null) { + $errors[$field] = $problem ?? 'Divi lehnt den Wert ab'; return null; } - $normalized = ThemeOptionSpec::normalize($key, $value); $sanitized = $this->options->sanitize($key, $normalized); if (! is_int($sanitized) && ! is_float($sanitized) && ! is_string($sanitized)) { $errors[$field] = 'Divi lehnt den Wert ab'; diff --git a/tests/Unit/Integrations/Divi/Design/DiviThemeOptionsUpdateAbilityTest.php b/tests/Unit/Integrations/Divi/Design/DiviThemeOptionsUpdateAbilityTest.php index fef9be7..ae5371a 100644 --- a/tests/Unit/Integrations/Divi/Design/DiviThemeOptionsUpdateAbilityTest.php +++ b/tests/Unit/Integrations/Divi/Design/DiviThemeOptionsUpdateAbilityTest.php @@ -152,6 +152,14 @@ final class DiviThemeOptionsUpdateAbilityTest extends TestCase self::assertSame(ThemeOptionBook::fromDivi($this->stored)->rev(), $result['design_rev']); } + public function testAFontNameIsTrimmedBeforeTheCatalogCheck(): void + { + $result = $this->confirmed($this->ability(self::snapshots()), ['set' => ['heading_font' => ' Roboto']])[1]; + + self::assertSame('theme_options-1', $result['snapshot_id']); + self::assertSame('Roboto', $this->stored['heading_font']); + } + /** Only fonts reach the builder (W7). */ public function testSizesOnlyWarnAboutTheWholeWebsite(): void {