fix(style): match names exactly in StyleByNamePlugin - #553
Merged
Merged
Conversation
`updateStyle` and `resetStyle` accept `string | string[]` and forwarded the parameter to
`BpmnElementsSearcher.getElementsByNames` through an `as string[]` cast. That searcher filters with
`names.includes(element.name)`, so a single name passed as a plain string ran `String.prototype.includes` instead of
`Array.prototype.includes`, turning the exact match into a substring match. `updateStyle('end event 10', ...)` also
styled the element named `end event 1`.
Normalize the parameter to an array rather than lying to the compiler, so both branches of the documented signature go
through `Array.prototype.includes`.
11 tasks
|
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 join this conversation on GitHub.
Already have an account?
Sign in to comment
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.



Problem
StyleByNamePlugin.updateStyleandStyleByNamePlugin.resetStyleacceptstring | string[], and both forwarded the parameter toBpmnElementsSearcher.getElementsByNamesthrough anas string[]cast.That searcher filters with
names.includes(element.name). When the cast hides a plain string, this runsString.prototype.includesinstead ofArray.prototype.includes, so the exact match silently becomes a substring match.With the names of the
search-elementsfixture,updateStyle('end event 10', ...)styles bothend event 10andend event 1. Passing a single name as a string is part of the documented signature, so this is reachable from a supported call.The existing tests passed only by chance: none of the names they use is a substring of another.
Fix
Normalize the parameter to an array instead of lying to the compiler, so both branches of the documented signature go through
Array.prototype.includes. No signature or behavior change for the array branch.Tests
One regression test per method, using the
end event 1andend event 10pair already present in the fixture. Both fail before the fix, withEvent_1hr2hqxwrongly included in the result.Notes
BpmnElementsSearcher.getElementsByNameskeeps itsstring[]signature. Widening it tostring | string[]would remove the trap for every other caller, including untyped JavaScript consumers, but that is an addition to the public API rather than a fix, so it is left for a later change.Found while writing the plugin system analysis in #552, section 2.3.