refined-github/refined-github · error · Error
Invalid compare URL format
Error message
Invalid compare URL format
What it means
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.
Source
Thrown at source/github-helpers/parse-compare-url.ts:33
};
const compareRegex = /compare[/](?<baseBranch>[^.]+)[.][.][.]?(?<heads>.+)/;
export default function parseCompareUrl(pathname: string): Comparison | undefined {
const base = getRepo(pathname)!;
const match = compareRegex.exec(base.path);
if (match === null) {
return;
}
const {baseBranch, heads} = match.groups!;
const headParts = heads.split(':');
const headBranch = headParts.pop()!; // Branch is always last, or the only one
const headOwner = headParts.shift() ?? base.owner; // The owner is first, or it's the same as the base
const headName = headParts.pop() ?? base.name; // The repo is first or middle, or it's the same as the base
if (headParts.length > 0) {
throw new Error('Invalid compare URL format');
}
const headRepo: NameWithOwner = `${headOwner}/${headName}`;
return {
base: {
repo: base.nameWithOwner,
branch: baseBranch,
},
head: {
repo: headRepo,
branch: headBranch,
},
isCrossRepo: headRepo !== base.nameWithOwner,
};
}
View on GitHub (pinned to 73afd11264)
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
Example fix
// before
const {base, head} = parseCompareUrl(location.pathname);
// after
const head = location.pathname.split('...')[1] ?? '';
if (head.split(':').length > 3) continue; // skip malformed compare URLs
const parsed = parseCompareUrl(location.pathname); Defensive patterns
Strategy: validation
Validate before calling
const head = url.split('...')[1] ?? '';
const parts = head.split(':');
const isValid = parts.length >= 1 && parts.length <= 3;
if (!isValid) return null; Type guard
const isParseableCompareHead = (head: string): boolean => head.split(':').length <= 3; Try / catch
try {
const parsed = parseCompareUrl(pathname);
} catch (error) {
if (error instanceof Error && error.message === 'Invalid compare URL format') return;
throw error;
} Prevention
- Validate compare URL shape before parsing
- Avoid colons in generated branch names
When it happens
Trigger: 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'.
Common situations: 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.
Related errors
AI-assisted analysis of refined-github/refined-github@73afd11264 (2026-08-27).
Data as JSON: /api/errors/cea59aa9b2c3b4c4.
Report an issue: GitHub.