{"record":{"id":"f85d0d14a2f912c7","repo":"symfony/routing","slug":"cannot-use-utf-8-route-patterns-without-setting-the-utf8","errorCode":null,"errorMessage":"Cannot use UTF-8 route patterns without setting the \"utf8\" option for route \"%s\".","messagePattern":"Cannot use UTF-8 route patterns without setting the \"utf8\" option for route \"(.+?)\"\\.","errorType":"exception","errorClass":"LogicException","httpStatus":null,"severity":"error","filePath":"RouteCompiler.php","lineNumber":118,"sourceCode":"            $hostRegex,\n            $hostTokens,\n            $hostVariables,\n            array_unique($variables)\n        );\n    }\n\n    private static function compilePattern(Route $route, string $pattern, bool $isHost): array\n    {\n        $tokens = [];\n        $variables = [];\n        $matches = [];\n        $pos = 0;\n        $defaultSeparator = $isHost ? '.' : '/';\n        $useUtf8 = preg_match('//u', $pattern);\n        $needsUtf8 = $route->getOption('utf8');\n\n        if (!$needsUtf8 && $useUtf8 && preg_match('/[\\x80-\\xFF]/', $pattern)) {\n            throw new \\LogicException(\\sprintf('Cannot use UTF-8 route patterns without setting the \"utf8\" option for route \"%s\".', $route->getPath()));\n        }\n        if (!$useUtf8 && $needsUtf8) {\n            throw new \\LogicException(\\sprintf('Cannot mix UTF-8 requirements with non-UTF-8 pattern \"%s\".', $pattern));\n        }\n\n        // Match all variables enclosed in \"{}\" and iterate over them. But we only want to match the innermost variable\n        // in case of nested \"{}\", e.g. {foo{bar}}. This in ensured because \\w does not match \"{\" or \"}\" itself.\n        preg_match_all('#\\{(!)?([\\w\\x80-\\xFF]+)\\}#', $pattern, $matches, \\PREG_OFFSET_CAPTURE | \\PREG_SET_ORDER);\n        foreach ($matches as $match) {\n            $important = $match[1][1] >= 0;\n            $varName = $match[2][0];\n            // get all static text preceding the current variable\n            $precedingText = substr($pattern, $pos, $match[0][1] - $pos);\n            $pos = $match[0][1] + \\strlen($match[0][0]);\n\n            if (!\\strlen($precedingText)) {\n                $precedingChar = '';\n            } elseif ($useUtf8) {","sourceCodeStart":100,"sourceCodeEnd":136,"githubUrl":"https://github.com/symfony/routing/blob/83fa223250b50f4f018c011e101c330e65ac63cc/RouteCompiler.php#L100-L136","documentation":"compilePattern detects that the route pattern (path or host) contains UTF-8 characters (high bytes \\x80-\\xFF) but the route's \"utf8\" option is not enabled. Since UTF-8 patterns require different regex matching, the compiler refuses to guess and throws a LogicException naming the route. This guard was introduced in Symfony 4.2/5.0 when UTF-8 route support became opt-in.","triggerScenarios":"Compiling a route whose path or host contains non-ASCII characters (e.g. '/café/{name}') while the route's utf8 option is false/unset — e.g. new Route('/café/{name}') without ['utf8' => true].","commonSituations":"Localized/multilingual routes with accented or non-Latin characters; apps migrated from Symfony <4 where UTF-8 was implicit; routes loaded from config files saved in UTF-8 with special characters.","solutions":["Set the utf8 option on the route: new Route('/café/{name}', options: ['utf8' => true]).","In YAML, add options: { utf8: true } to the route definition.","Alternatively, URL-encode or transliterate the pattern so it contains only ASCII characters.","In Symfony 6.0+, UTF-8 is always enabled, so upgrade to remove the option requirement."],"exampleFix":"// before\n$route = new Route('/café/{name}');\n\n// after\n$route = new Route('/café/{name}', options: ['utf8' => true]);","handlingStrategy":"validation","validationCode":"$path = $route->getPath();\n$hasHighBytes = (bool) preg_match('/[\\x80-\\xFF]/', $path);\nif ($hasHighBytes && !$route->getOption('utf8')) {\n    $route->setOption('utf8', true); // or fail validation\n}","typeGuard":null,"tryCatchPattern":"try {\n    $compiled = (new RouteCompiler())->compile($route);\n} catch (\\LogicException $e) {\n    // enable utf8 or transliterate the pattern, then retry\n}","preventionTips":["Enable the utf8 option globally when your app serves non-ASCII URLs.","Prefer percent-encoded/ASCII patterns in shared libraries.","On Symfony 6+, UTF-8 is always on — plan the upgrade to eliminate the option."],"tags":["routing","symfony","utf8","configuration"],"backgroundTag":"conflicting-config-options","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"}