Don't load unknown icon names as image paths#3837
Merged
Merged
Conversation
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.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Changes in this pull request
Resolves #3834
normalizeIcon()andtoElementIcon()treated any string that isn't a registered icon as an image path, so legacypimcore_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 usestype: 'path'only for real path/URL values; otherwise it warns and renders no icon.Additional info