fix: fall back to default branch when resolving relative image URLs

The Anonymize form's preview built the readme baseUrl as
"https://github.com/<owner>/<repo>/raw/<source.branch>/". When the
form rendered before the branch field had populated (initial load,
or while waiting on getBranches), the URL became ".../raw//" and
the browser collapsed the empty segment, fetching ".../raw/<file>"
instead of ".../raw/<branch>/<file>". Relative <img src="./X">
references then 404'd against a path with no branch — exactly the
"branch missing" pattern in #407.

Fall back to details.defaultBranch (then "main") so the base URL is
always well-formed.

Fixes #407.
This commit is contained in:
tdurieux
2026-05-04 12:01:56 +02:00
parent 62a2c1cd5c
commit 7ace730960
2 changed files with 11 additions and 2 deletions
+10 -1
View File
@@ -1460,7 +1460,16 @@ angular
let baseUrl = "";
try {
const o = parseGithubUrl($scope.sourceUrl);
baseUrl = `https://github.com/${o.owner}/${o.repo}/raw/${$scope.source.branch}/`;
// Fall back to the repo's default branch when source.branch
// hasn't loaded yet — without this, relative <img src="./X">
// resolved against a baseUrl like ".../raw//" (no branch
// segment), so the browser fetched ".../raw/X" and 404'd
// (#407).
const branch =
$scope.source.branch ||
($scope.details && $scope.details.defaultBranch) ||
"main";
baseUrl = `https://github.com/${o.owner}/${o.repo}/raw/${branch}/`;
} catch (_) { /* fall through with empty base */ }
const html = renderMD($scope.anonymize_readme, baseUrl);
$scope.html_readme = $sce.trustAsHtml(html);
+1 -1
View File
File diff suppressed because one or more lines are too long