{"record":{"id":"a2f5c978e766ed0f","repo":"symfony/http-foundation","slug":"invalid-uri-path-is-malformed","errorCode":null,"errorMessage":"Invalid URI: Path is malformed.","messagePattern":"Invalid URI: Path is malformed\\.","errorType":"exception","errorClass":"BadRequestException","httpStatus":400,"severity":"error","filePath":"Request.php","lineNumber":454,"sourceCode":"        }\n\n        if (isset($components['user'])) {\n            $server['PHP_AUTH_USER'] = $components['user'];\n        }\n\n        if (isset($components['pass'])) {\n            $server['PHP_AUTH_PW'] = $components['pass'];\n        }\n\n        if ('' === $path = $components['path'] ?? '') {\n            $components['path'] = '/';\n        } elseif (!isset($components['scheme']) && !isset($components['host']) && '/' !== $path[0]) {\n            if (false !== $pos = strpos($path, '/')) {\n                $path = substr($path, 0, $pos);\n            }\n\n            if (str_contains($path, ':')) {\n                throw new BadRequestException('Invalid URI: Path is malformed.');\n            }\n        }\n\n        switch (strtoupper($method)) {\n            case 'POST':\n            case 'PUT':\n            case 'DELETE':\n            case 'QUERY':\n                if (!isset($server['CONTENT_TYPE'])) {\n                    $server['CONTENT_TYPE'] = 'application/x-www-form-urlencoded';\n                }\n                // no break\n            case 'PATCH':\n                $request = $parameters;\n                $query = [];\n                break;\n            default:\n                $request = [];","sourceCodeStart":436,"sourceCodeEnd":472,"githubUrl":"https://github.com/symfony/http-foundation/blob/5aea19cd678fa4140f6108406f1096de5e9ed6e4/Request.php#L436-L472","documentation":"Request::create() parses the given URI. When a URI has no scheme and no host, it is treated as a target path; if such a string contains a ':' before any '/' (e.g. 'localhost:8080/foo'), it is not a valid absolute path, so the library throws BadRequestException('Invalid URI: Path is malformed.') to reject it early.","triggerScenarios":"Calling Request::create() with a relative target that includes an authority-like prefix without a scheme, e.g. Request::create('localhost:8080/path') or Request::create('host:port'), where strpos($path, ':') matches before any '/'.","commonSituations":"Building test requests from host:port strings copied from a dev server; forgetting the 'http://' scheme; concatenating base URLs incorrectly in functional tests or kernel simulations; passing values from env vars like HOST:PORT directly as a URI.","solutions":["Prepend the missing scheme/host: Request::create('http://localhost:8080/path').","If a path-only request is intended, remove the host:port prefix and pass '/path' instead.","Build the URI with http_build_url() or implode of scheme+'://'+host to avoid manual string errors.","Validate the URI with filter_var($uri, FILTER_VALIDATE_URL) or parse_url before passing it to create()."],"exampleFix":"// before\n$request = Request::create('localhost:8080/api/users');\n\n// after\n$request = Request::create('http://localhost:8080/api/users');","handlingStrategy":"validation","validationCode":"$uri = 'localhost:8080/api';\n$parts = parse_url($uri);\nif ($parts === false || (!isset($parts['scheme']) && ($uri[0] ?? '') !== '/' && str_contains(explode('/', $uri)[0], ':'))) {\n    $uri = 'http://' . $uri;\n}\n$request = Request::create($uri);","typeGuard":null,"tryCatchPattern":"try {\n    $request = Request::create($uri);\n} catch (BadRequestException $e) {\n    $request = Request::create('http://' . ltrim($uri, '/'));\n}","preventionTips":["Always pass scheme-qualified URIs to Request::create() in tests.","Validate URIs with parse_url()/filter_var(FILTER_VALIDATE_URL) before use.","Never hand-concatenate host:port strings into a 'path'."],"tags":["http","request","uri-parsing","symfony"],"backgroundTag":"invalid-url-format","analyzedSha":"5aea19cd678fa4140f6108406f1096de5e9ed6e4","analyzedAt":"2026-09-13T01:52:22.855Z","contentChangedAt":"2026-09-13T01:52:22.855Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}