Skip to content

Don't load unknown icon names as image paths#3837

Merged
markus-moser merged 9 commits into
2025.4from
fix/icon-fallback-404-3834
Jun 30, 2026
Merged

Don't load unknown icon names as image paths#3837
markus-moser merged 9 commits into
2025.4from
fix/icon-fallback-404-3834

Conversation

@markus-moser

@markus-moser markus-moser commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

Changes in this pull request

Resolves #3834

normalizeIcon() and toElementIcon() treated any string that isn't a registered icon as an image path, so legacy pimcore_icon_* classes (e.g. on the demo's workflow report menu shortcuts) rendered as <img src="…"> and 404'd.

They now share a resolveIconString() helper that uses type: 'path' only for real path/URL values; otherwise it warns and renders no icon.

Additional info

  • Unit tests added.

markus-moser and others added 9 commits June 30, 2026 09:51
normalizeIcon() classified any string not registered in the icon library
as a `path`, so legacy `pimcore_icon_*` CSS classes (e.g. the default
workflow-action icon on the demo's custom-report menu shortcuts) were
rendered as `<img src="pimcore_icon_workflow_action">`. That resolves to
a wrong relative URL under /pimcore-studio/ and triggers a 404.

Only treat a string as a path when it actually looks like one (contains a
slash, a URL scheme, or an image extension). Otherwise console.warn and
skip the icon so no broken request is made. Registered library names and
explicit ElementIcon objects are unaffected.
toElementIcon() had the same blind `type: 'path'` fallback as normalizeIcon():
any string not found in the icon-set registry was turned into an <img src>,
so legacy `pimcore_icon_*` classes would 404 there too (e.g. class-definition
icons rendered via the icon selector).

Extract the path heuristic into a shared `utils/icon-path.ts` (looksLikeIconPath)
and use it in both normalizeIcon() and toElementIcon(): treat a string as a path
only when it looks like one, otherwise console.warn and return no icon.
normalizeIcon() and toElementIcon() had a near-identical name/path/warn-skip
block. Extract it into resolveIconString(value, isKnownIcon, source) in
utils/icon-path.ts; each function now only wires its own "known icon" lookup
(icon library vs icon-set registry) and empty/passthrough handling.

The shared classification is now unit-tested once (icon-path.test.ts); the
per-function tests cover only their own branches.
Move looksLikeIconPath + resolveIconString into utils/normalize-icon.ts and
have toElementIcon import resolveIconString from there, instead of keeping a
standalone utils/icon-path.ts. normalize-icon.ts is the natural home for icon
string resolution. Tests merged into normalize-icon.test.ts.
@sonarqubecloud

Copy link
Copy Markdown

@markus-moser markus-moser changed the title Fix #3834: don't render unknown icon classes as broken image paths (404) Fix #3834: don't load unknown icon names as image paths Jun 30, 2026
@markus-moser markus-moser changed the title Fix #3834: don't load unknown icon names as image paths Don't load unknown icon names as image paths Jun 30, 2026
@markus-moser markus-moser marked this pull request as ready for review June 30, 2026 13:48
@markus-moser markus-moser merged commit 339ed54 into 2025.4 Jun 30, 2026
7 checks passed
@markus-moser markus-moser deleted the fix/icon-fallback-404-3834 branch June 30, 2026 13:48
@github-actions github-actions Bot locked and limited conversation to collaborators Jun 30, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant