Skip to content

Fix flag SVG 404 by resolving asset bundle base URL alias - #58

Merged
luke- merged 1 commit into
masterfrom
fix/flag-asset-url-alias
Jun 16, 2026
Merged

Fix flag SVG 404 by resolving asset bundle base URL alias#58
luke- merged 1 commit into
masterfrom
fix/flag-asset-url-alias

Conversation

@luke-

@luke- luke- commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

Problem

Bundled team flag SVGs 404 on HumHub develop, e.g.
…/kickoff/c/@web/assets/<hash>/flags/1f1f2-1f1fd.svg — note the literal @web in the path.

Cause

views/competition/_team_badge.php built the flag URL by concatenating the published asset bundle's baseUrl straight into the <img src>:

$baseUrl = Assets::register($this)->baseUrl;
$flagUrl = "{$baseUrl}/flags/{$fileStem}.svg";

A bundle's baseUrl is not guaranteed to be a final URL. HumHub develop's new filesystem-backed AssetManager sets the base URL from the assets mount config without resolving aliases ($this->baseUrl = Yii::$app->fs->getAssetsMountConfig()->getBaseUrl()), so it is the literal path alias @web/assets/<hash>. HumHub resolves that alias only when it emits <link>/<script> tags — Html::cssFile()/Html::jsFile() run the URL through Url::to(). The hand-built <img src> skipped that step, so the literal @web/... ended up in the markup and the browser resolved it relative to the current page (…/kickoff/c/@web/assets/…) → 404. Registered CSS was unaffected for exactly this reason. On stable it happened to work because the older asset manager resolved baseUrl at init.

Note: AssetManager::getAssetUrl($bundle, 'flags/x.svg') would not fix this — it returns $bundle->baseUrl . '/' . $asset and isn't overridden on develop, so it yields the same unresolved @web/....

Fix

Resolve the flag URL through Url::to(), mirroring HumHub's own asset-URL handling (Html::cssFile()Url::to()). Extracted into Assets::flagUrl(). This is a no-op for the already-resolved /assets/<hash> form on stable, so it is fully backwards-compatible, and also handles absolute base URLs (console/cron render) and the app-at-root case (@web = '').

Added AssetsTest covering the unresolved-alias and already-resolved cases.

CI didn't catch this because no test renders the badge.

@luke-
luke- force-pushed the fix/flag-asset-url-alias branch from 9a8152e to 8514cad Compare June 16, 2026 18:38
The team badge built the flag URL by concatenating the published asset
bundle's baseUrl straight into the <img src>. That baseUrl is not
guaranteed to be a final URL: HumHub develop's filesystem-backed asset
manager sets it to the unresolved path alias `@web/assets/<hash>` and only
resolves the alias when it emits <link>/<script> tags (Html::cssFile()/
Html::jsFile() run the URL through Url::to()). The hand-built <img src>
bypassed that, so the literal `@web/...` was emitted and the browser
resolved it against the current page URL (`…/kickoff/c/@web/assets/…`),
404ing the flag. Registered CSS was unaffected because it goes through
Html::cssFile()→Url::to().

Resolve the flag URL through Url::to(), mirroring HumHub's own asset-URL
handling (no-op for the already-resolved `/assets/<hash>` form on stable).
Extracted into Assets::flagUrl() and covered by a unit test.
@luke-
luke- force-pushed the fix/flag-asset-url-alias branch from 8514cad to 7c35787 Compare June 16, 2026 21:07
@luke-
luke- merged commit 4bd3b45 into master Jun 16, 2026
17 checks passed
@luke-
luke- deleted the fix/flag-asset-url-alias branch June 16, 2026 21:14
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