{"record":{"id":"b0815b776b4c6fce","repo":"symfony/symfony","slug":"the-url-s-is-not-valid","errorCode":null,"errorMessage":"The URL \"%s\" is not valid.","messagePattern":"The URL \"(.+?)\" is not valid\\.","errorType":"validation","errorClass":"InvalidArgumentException","httpStatus":null,"severity":"error","filePath":"src/Symfony/Component/BrowserKit/Cookie.php","lineNumber":150,"sourceCode":"        }\n\n        [$name, $value] = explode('=', array_shift($parts), 2);\n\n        $values = [\n            'name' => trim($name),\n            'value' => trim($value),\n            'expires' => null,\n            'path' => '/',\n            'domain' => '',\n            'secure' => false,\n            'httponly' => false,\n            'passedRawValue' => true,\n            'samesite' => null,\n        ];\n\n        if (null !== $url) {\n            if (false === ($urlParts = parse_url($url)) || !isset($urlParts['host'])) {\n                throw new InvalidArgumentException(\\sprintf('The URL \"%s\" is not valid.', $url));\n            }\n\n            $values['domain'] = $urlParts['host'];\n            $values['path'] = isset($urlParts['path']) ? substr($urlParts['path'], 0, strrpos($urlParts['path'], '/')) : '';\n        }\n\n        foreach ($parts as $part) {\n            $part = trim($part);\n\n            if ('secure' === strtolower($part)) {\n                // Ignore the secure flag if the original URI is not given or is not HTTPS\n                if (null === $url || !isset($urlParts['scheme']) || 'https' !== $urlParts['scheme']) {\n                    continue;\n                }\n\n                $values['secure'] = true;\n\n                continue;","sourceCodeStart":132,"sourceCodeEnd":168,"githubUrl":"https://github.com/symfony/symfony/blob/698e28026c22cf35d032cdb6e800db48b1535790/src/Symfony/Component/BrowserKit/Cookie.php#L132-L168","documentation":"Thrown by Cookie::fromString() when the optional \\$url argument cannot be parsed by parse_url() or has no 'host' component. The URL is used to derive the cookie's domain and path, so a host-less or malformed URL is rejected.","triggerScenarios":"Calling Cookie::fromString('sid=1', '//relative/path') or Cookie::fromString('sid=1', 'not a url') — anything where parse_url() returns false or omits host (Cookie.php:149).","commonSituations":"Passing a relative URL, a bare path, or a mistyped scheme to fromString(). Common when the cookie is parsed from a request whose full absolute URL wasn't captured.","solutions":["Pass an absolute URL with a scheme and host (e.g. 'https://example.com/path').","Omit the \\$url argument entirely if you don't need domain/path derivation.","Resolve relative URLs to absolute before calling, e.g. via a URL resolver."],"exampleFix":"// before\n$cookie = Cookie::fromString('sid=1', '/admin');\n\n// after\n$cookie = Cookie::fromString('sid=1', 'https://example.com/admin');","handlingStrategy":"validation","validationCode":"// Pass an absolute URL with scheme + host, or omit \\$url.\n$parts = parse_url($url);\nif ($parts && isset($parts['host'])) {\n    $cookie = Cookie::fromString($header, $url);\n} else {\n    $cookie = Cookie::fromString($header); // no URL context\n}","typeGuard":"function isAbsoluteUrl(string $url): bool\n{\n    $p = parse_url($url);\n    return $p !== false && isset($p['host'], $p['scheme']);\n}","tryCatchPattern":"try {\n    $cookie = Cookie::fromString($header, $url);\n} catch (\\Symfony\\Component\\BrowserKit\\Exception\\InvalidArgumentException $e) {\n    // URL invalid; retry without URL context\n}","preventionTips":["Only pass absolute URLs (with scheme and host) to fromString().","Omit the \\$url argument when you don't need domain/path derivation.","Resolve relative URLs to absolute before parsing cookies."],"tags":["cookies","browser-kit","validation","url"],"analyzedSha":"698e28026c22cf35d032cdb6e800db48b1535790","analyzedAt":"2026-08-06T23:40:49.025Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}