{"record":{"id":"f9ac1b509fee0c0a","repo":"symfony/routing","slug":"invalid-characters-found-in-deprecation-template","errorCode":null,"errorMessage":"Invalid characters found in deprecation template.","messagePattern":"Invalid characters found in deprecation template\\.","errorType":"validation","errorClass":"InvalidArgumentException","httpStatus":null,"severity":"error","filePath":"Alias.php","lineNumber":59,"sourceCode":"        return $this->id;\n    }\n\n    /**\n     * Whether this alias is deprecated, that means it should not be referenced anymore.\n     *\n     * @param string $package The name of the composer package that is triggering the deprecation\n     * @param string $version The version of the package that introduced the deprecation\n     * @param string $message The deprecation message to use\n     *\n     * @return $this\n     *\n     * @throws InvalidArgumentException when the message template is invalid\n     */\n    public function setDeprecated(string $package, string $version, string $message): static\n    {\n        if ('' !== $message) {\n            if (preg_match('#[\\r\\n]|\\*/#', $message)) {\n                throw new InvalidArgumentException('Invalid characters found in deprecation template.');\n            }\n\n            if (!str_contains($message, '%alias_id%')) {\n                throw new InvalidArgumentException('The deprecation template must contain the \"%alias_id%\" placeholder.');\n            }\n        }\n\n        $this->deprecation = [\n            'package' => $package,\n            'version' => $version,\n            'message' => $message ?: 'The \"%alias_id%\" route alias is deprecated. You should stop using it, as it will be removed in the future.',\n        ];\n\n        return $this;\n    }\n\n    public function isDeprecated(): bool\n    {","sourceCodeStart":41,"sourceCodeEnd":77,"githubUrl":"https://github.com/symfony/routing/blob/83fa223250b50f4f018c011e101c330e65ac63cc/Alias.php#L41-L77","documentation":"Alias::setDeprecated() validates the deprecation message template because it is injected into compiled PHP/doc comments of generated containers. This error means the template contains characters (newlines, carriage returns, or the comment terminator '*/') that would break or exploit the generated code structure.","triggerScenarios":"Calling setDeprecated() on a Symfony DI Alias with a $message containing '\\n', '\\r', or '*/'.","commonSituations":"Building a deprecation message by interpolating a multi-line doc comment, pasting a template containing a comment close sequence, or programmatically joining messages with newlines.","solutions":["Remove all newline/carriage-return characters and any '*/' sequence from the message template.","Collapse the message to a single line, e.g. str_replace([\"\\r\",\"\\n\"], ' ', $message).","Keep the required '%alias_id%' placeholder in the template to avoid the follow-up error.","If the message comes from user/config input, sanitize it before passing to setDeprecated()."],"exampleFix":"// before\n$alias->setDeprecated('acme/pkg', '2.0', \"The service is deprecated.\\nUse %alias_id% instead.\");\n// after\n$alias->setDeprecated('acme/pkg', '2.0', 'The service is deprecated. Use %alias_id% instead.');","handlingStrategy":"validation","validationCode":"if (preg_match('#[\\r\\n]|\\*/#', $message) || !str_contains($message, '%alias_id%')) {\n    throw new InvalidArgumentException('Deprecation template must be single-line and contain %alias_id%.');\n}","typeGuard":"function isValidDeprecationTemplate(string $m): bool { return $m === '' || (!preg_match('#[\\r\\n]|\\*/#', $m) && str_contains($m, '%alias_id%')); }","tryCatchPattern":"try { $alias->setDeprecated($pkg, $ver, $tpl); } catch (InvalidArgumentException $e) { /* log & use default template */ }","preventionTips":["Keep deprecation templates as single-line string constants","Always include %alias_id% in any custom template","Sanitize config/user-provided messages before passing"],"tags":["php","symfony-di","validation"],"backgroundTag":"invalid-argument-value","analyzedSha":"83fa223250b50f4f018c011e101c330e65ac63cc","analyzedAt":"2026-09-14T03:19:46.280Z","contentChangedAt":"2026-09-14T03:19:46.280Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}