Skip to content

Fix support absolute GitHub URLs in path parser#249

Open
envico801 wants to merge 1 commit into
AminoffZ:mainfrom
envico801:fix/handle-absolute-github-urls
Open

Fix support absolute GitHub URLs in path parser#249
envico801 wants to merge 1 commit into
AminoffZ:mainfrom
envico801:fix/handle-absolute-github-urls

Conversation

@envico801

Copy link
Copy Markdown

Fix: Handle absolute GitHub URLs in file links

This PR fixes an issue where file sizes could incorrectly display as "..." when browsing certain forks or navigating through GitHub's SPA interface.

Root cause

The extension currently assumes GitHub file links are always relative URLs:

/owner/repo/tree/main/path/to/file

However, GitHub sometimes injects absolute URLs into the DOM instead:

https://github.com/owner/repo/tree/main/path/to/file

get-path-object.ts parses paths using index-based splitting:

const paths = path.split('/');
const rawPath = paths.slice(5)?.join('/');

This works for relative paths:

["", "owner", "repo", "tree", "main", "src"]

but fails for absolute URLs:

["https:", "", "github.com", "owner", "repo", "tree", "main", "src"]

Because the indices shift, the parser extracts invalid paths such as:

tree/main/src

instead of:

src

This causes repository tree lookups to fail, resulting in "..." placeholders.

This can be reproduced with:


Solution

Normalize all incoming URLs before parsing.

If the path is absolute:

  • extract only the pathname using URL.pathname
  • preserve the existing relative-path parsing logic
if (path.startsWith('http') || path.startsWith('//')) {
  path = new URL(path, window.location.origin).pathname;
}

This guarantees consistent parsing regardless of how GitHub renders the link.


⚠️ Important

This PR assumes that #246 is already merged or will be, so part of that PR is present on this one, due to both touching the same file.


Before:

2026-05-07_14-28-43

After:

2026-05-07_14-30-30

Handle cases where GitHub renders absolute URLs instead of relative
paths in repository file links, which can occur on forks and certain
SPA navigation flows.

Normalize links to pathname-only URLs before performing index-based
path extraction to ensure consistent repository path parsing.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant