{"record":{"id":"2d43dceae823e13e","repo":"symfony/translation","slug":"invalid-s-locale","errorCode":null,"errorMessage":"Invalid \"%s\" locale.","messagePattern":"Invalid \"(.+?)\" locale\\.","errorType":"exception","errorClass":"InvalidArgumentException","httpStatus":null,"severity":"error","filePath":"LocaleFallbackProvider.php","lineNumber":92,"sourceCode":"            if ($fallback === $originLocale) {\n                continue;\n            }\n\n            $locales[$fallback] = $fallback;\n        }\n\n        return array_keys($locales);\n    }\n\n    /**\n     * Asserts that the locale is valid, throws an Exception if not.\n     *\n     * @throws InvalidArgumentException If the locale contains invalid characters\n     */\n    public static function validateLocale(string $locale): void\n    {\n        if (!preg_match('/^[a-z0-9@_\\.\\-]*$/i', $locale)) {\n            throw new InvalidArgumentException(\\sprintf('Invalid \"%s\" locale.', $locale));\n        }\n    }\n}\n","sourceCodeStart":74,"sourceCodeEnd":96,"githubUrl":"https://github.com/symfony/translation/blob/ae9e8a51bc29780d63c7f9efd6005d7c875e100b/LocaleFallbackProvider.php#L74-L96","documentation":"Static guard in LocaleFallbackProvider (Translation provider layer) that rejects locale strings containing characters outside [a-zA-Z0-9@_.-]. It is called when constructing the provider and when computing fallback locales, because an invalid locale would silently produce broken catalogue lookups.","triggerScenarios":"Passing a locale containing spaces, slashes, commas, uppercase-extended symbols or other invalid characters to new LocaleFallbackProvider(...), to fallback locale configuration (computeFallbackLocales), or via helpers like assertValidLocale.","commonSituations":"Environment variables or config containing 'en_US;de_DE' lists with semicolons, URLs accidentally used as locales, locales with spaces ('en US'), or user-supplied locale input injected into fallback configuration.","solutions":["Fix the locale string so it matches /^[a-z0-9@_\\.\\-]*$/i (e.g. 'en', 'en_US', 'fr@posix').","If passing multiple locales, pass an array or split on a valid separator instead of embedding them in one string.","Trim whitespace and strip query fragments from user-supplied locales before use.","Call LocaleFallbackProvider::validateLocale($locale) yourself in config bootstrapping to fail early with a clearer message."],"exampleFix":"// before\nnew LocaleFallbackProvider($loader, 'en_US de_DE');\n\n// after\nnew LocaleFallbackProvider($loader, 'en_US');","handlingStrategy":"validation","validationCode":"if (!preg_match('/^[a-z0-9@_\\.\\-]*$/i', $locale)) {\n    throw new \\InvalidArgumentException(\"Locale '$locale' contains invalid characters\");\n}","typeGuard":"function isValidLocale(string $locale): bool { return (bool) preg_match('/^[a-z0-9@_\\.\\-]*$/i', $locale); }","tryCatchPattern":"try {\n    $provider = new LocaleFallbackProvider($loader, $locale);\n} catch (\\InvalidArgumentException $e) {\n    // sanitize/fix $locale before retrying\n}","preventionTips":["Normalize and trim locale input from env vars and HTTP requests.","Never pack multiple locales into one string; use arrays.","Reuse LocaleFallbackProvider::validateLocale in your own config validation."],"tags":["locale","validation","invalid-argument","i18n"],"backgroundTag":"invalid-identifier-format","analyzedSha":"ae9e8a51bc29780d63c7f9efd6005d7c875e100b","analyzedAt":"2026-09-15T22:29:15.305Z","contentChangedAt":"2026-09-15T22:29:15.305Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}