{"record":{"id":"cea59aa9b2c3b4c4","repo":"refined-github/refined-github","slug":"invalid-compare-url-format","errorCode":null,"errorMessage":"Invalid compare URL format","messagePattern":"Invalid compare URL format","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"source/github-helpers/parse-compare-url.ts","lineNumber":33,"sourceCode":"};\n\nconst compareRegex = /compare[/](?<baseBranch>[^.]+)[.][.][.]?(?<heads>.+)/;\nexport default function parseCompareUrl(pathname: string): Comparison | undefined {\n\tconst base = getRepo(pathname)!;\n\n\tconst match = compareRegex.exec(base.path);\n\tif (match === null) {\n\t\treturn;\n\t}\n\n\tconst {baseBranch, heads} = match.groups!;\n\tconst headParts = heads.split(':');\n\tconst headBranch = headParts.pop()!; // Branch is always last, or the only one\n\tconst headOwner = headParts.shift() ?? base.owner; // The owner is first, or it's the same as the base\n\tconst headName = headParts.pop() ?? base.name; // The repo is first or middle, or it's the same as the base\n\n\tif (headParts.length > 0) {\n\t\tthrow new Error('Invalid compare URL format');\n\t}\n\n\tconst headRepo: NameWithOwner = `${headOwner}/${headName}`;\n\n\treturn {\n\t\tbase: {\n\t\t\trepo: base.nameWithOwner,\n\t\t\tbranch: baseBranch,\n\t\t},\n\t\thead: {\n\t\t\trepo: headRepo,\n\t\t\tbranch: headBranch,\n\t\t},\n\t\tisCrossRepo: headRepo !== base.nameWithOwner,\n\t};\n}\n","sourceCodeStart":15,"sourceCodeEnd":50,"githubUrl":"https://github.com/refined-github/refined-github/blob/73afd11264c0243e077d20d07e5bc048feb2ba7b/source/github-helpers/parse-compare-url.ts#L15-L50","documentation":"parseCompareUrl splits the head segment of a compare URL (owner:repo:branch) and throws when, after extracting branch, owner, and repo, leftover parts remain — meaning the URL has an impossible number of colon-separated segments.","triggerScenarios":"A compare URL whose head part contains more than 3 segments, e.g. /compare/base...a:b:c:d, or unexpected colons in branch names combined with explicit owner/repo. Well-formed heads are 'branch', 'owner:branch', or 'owner:repo:branch'.","commonSituations":"Branch names containing colons (rare/illegal in Git but possible in mangled URLs), user-pasted or programmatically constructed compare URLs with extra separators, URL encoding bugs producing stray colons.","solutions":["Validate the compare URL shape before parsing (head must have 1-3 colon-separated parts)","URL-encode or strip illegal colons from branch names","Handle the throw and fall back to treating the whole head as a branch name"],"exampleFix":"// before\nconst {base, head} = parseCompareUrl(location.pathname);\n\n// after\nconst head = location.pathname.split('...')[1] ?? '';\nif (head.split(':').length > 3) continue; // skip malformed compare URLs\nconst parsed = parseCompareUrl(location.pathname);","handlingStrategy":"validation","validationCode":"const head = url.split('...')[1] ?? '';\nconst parts = head.split(':');\nconst isValid = parts.length >= 1 && parts.length <= 3;\nif (!isValid) return null;","typeGuard":"const isParseableCompareHead = (head: string): boolean => head.split(':').length <= 3;","tryCatchPattern":"try {\n\tconst parsed = parseCompareUrl(pathname);\n} catch (error) {\n\tif (error instanceof Error && error.message === 'Invalid compare URL format') return;\n\tthrow error;\n}","preventionTips":["Validate compare URL shape before parsing","Avoid colons in generated branch names"],"tags":["url-parsing","github","compare","validation"],"backgroundTag":"url-parse-invalid-format","analyzedSha":"73afd11264c0243e077d20d07e5bc048feb2ba7b","analyzedAt":"2026-08-27T22:35:47.934Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}