Skip to content

Fix browser extension broken links when branch is specified

Administrator requested to merge tj/browser-link into master

Created by: tjkandala

Fix #11057.

The Sourcegraph browser extension link used to break on the root directory of a repo when a branch was specified. This happened because we would throw an error when the path structure wasn't exactly: <empty>/<user>/<repo>/(blob | tree)/<commitID>/<path/to/file>

The href for the a.js-permalink-shortcut element on the root directory looks like this: "/sourcegraph/sourcegraph/tree/cff20a845c2263deacdcbf18e3b50e2b3c4af94c" (no path).

I added a check for page type in getFilePath() in order to allow tree pages to have an empty path. This resulted in a complication in resolveFileInfo() because it prepended all paths with a slash, so I made an exception for falsy strings.

Result: extension_master

The link shows up now. extension_branch

The link to the repository works. result_after_click

Merge request reports

Loading