{"record":{"id":"58cdd36d5bc23754","repo":"composer/composer","slug":"invalid-url-given-for-composer-repository-url","errorCode":null,"errorMessage":"Invalid url given for Composer repository: {url}","messagePattern":"Invalid url given for Composer repository: (.+?)","errorType":"exception","errorClass":"UnexpectedValueException","httpStatus":null,"severity":"error","filePath":"src/Composer/Repository/ComposerRepository.php","lineNumber":184,"sourceCode":"                // it is a local path, add file scheme\n                $repoConfig['url'] = 'file://'.$localFilePath;\n            } else {\n                // otherwise, assume http as the default protocol\n                $repoConfig['url'] = 'http://'.$repoConfig['url'];\n            }\n        }\n        $repoConfig['url'] = rtrim($repoConfig['url'], '/');\n        if ($repoConfig['url'] === '') {\n            throw new \\InvalidArgumentException('The repository url must not be an empty string');\n        }\n\n        if (str_starts_with($repoConfig['url'], 'https?')) {\n            $repoConfig['url'] = (extension_loaded('openssl') ? 'https' : 'http') . substr($repoConfig['url'], 6);\n        }\n\n        $urlBits = parse_url(strtr($repoConfig['url'], '\\\\', '/'));\n        if ($urlBits === false || empty($urlBits['scheme'])) {\n            throw new \\UnexpectedValueException('Invalid url given for Composer repository: '.Url::sanitize($repoConfig['url']));\n        }\n\n        if (!isset($repoConfig['options'])) {\n            $repoConfig['options'] = [];\n        }\n        if (isset($repoConfig['allow_ssl_downgrade']) && true === $repoConfig['allow_ssl_downgrade']) {\n            $this->allowSslDowngrade = true;\n        }\n\n        $this->options = $repoConfig['options'];\n        $this->url = $repoConfig['url'];\n\n        // force url for packagist.org to repo.packagist.org\n        if (Preg::isMatch('{^(?P<proto>https?)://packagist\\.org/?$}i', $this->url, $match)) {\n            $this->url = $match['proto'].'://repo.packagist.org';\n        }\n\n        $baseUrl = rtrim(Preg::replace('{(?:/[^/\\\\\\\\]+\\.json)?(?:[?#].*)?$}', '', $this->url), '/');","sourceCodeStart":166,"sourceCodeEnd":202,"githubUrl":"https://github.com/composer/composer/blob/6ffc1177404d0c50119c22dde6564a380f4a82c9/src/Composer/Repository/ComposerRepository.php#L166-L202","documentation":"After normalising the url, ComposerRepository parses it with parse_url() and requires a valid scheme. If parse_url returns false or there is no scheme, it throws UnexpectedValueException because it cannot decide how to fetch metadata. The url in the message is sanitised to avoid leaking credentials.","triggerScenarios":"A repository url that, after scheme-prefixing and slash-trimming, still has no parseable scheme — e.g. a url consisting only of a path fragment, or one containing characters that make parse_url fail. This typically happens when the input lacks a protocol and realpath() also fails (so the http:// default isn't added cleanly).","commonSituations":"Urls with backslashes or malformed characters; urls that are relative paths which don't resolve on disk; copy-paste of a url missing its protocol in an unusual form; typos like 'htps://'.","solutions":["Specify a full url with an explicit scheme, e.g. https://repo.example.com.","For local paths use an absolute filesystem path or a file:// URL.","Remove stray backslashes or encoded characters from the url."],"exampleFix":"// before\n{ \"type\": \"composer\", \"url\": \"repo.example.com\\\\packages.json\" }\n\n// after\n{ \"type\": \"composer\", \"url\": \"https://repo.example.com/packages.json\" }","handlingStrategy":"validation","validationCode":"$url = $config['url'] ?? '';\nif (parse_url((string) $url) === false || empty(parse_url((string) $url)['scheme'])) {\n    throw new \\InvalidArgumentException(\"Repository url has no valid scheme: {$url}\");\n}","typeGuard":"function hasValidScheme(string $url): bool {\n    $bits = parse_url(strtr($url, '\\\\', '/'));\n    return $bits !== false && !empty($bits['scheme']);\n}","tryCatchPattern":null,"preventionTips":["Always include the scheme (https:// or file://) in repository urls.","Avoid backslashes in urls; use forward slashes.","Run `composer validate` to surface malformed repository definitions."],"tags":["configuration","repository","url","validation"],"analyzedSha":"6ffc1177404d0c50119c22dde6564a380f4a82c9","analyzedAt":"2026-08-07T00:01:08.491Z","schemaVersion":2},"datasetVersion":"2026-08-07T02:17:10.218Z"}