Skip to content

fix(style): match names exactly in StyleByNamePlugin - #553

Merged
tbouffard merged 2 commits into
mainfrom
fix/style_by_name_substring_match
Aug 20, 2026
Merged

tbouffard merged 2 commits into
mainfrom
fix/style_by_name_substring_match

Conversation

@tbouffard

Copy link
Copy Markdown
Member

Problem

StyleByNamePlugin.updateStyle and StyleByNamePlugin.resetStyle accept string | string[], and both forwarded the parameter to BpmnElementsSearcher.getElementsByNames through an as string[] cast.

That searcher filters with names.includes(element.name). When the cast hides a plain string, this runs String.prototype.includes instead of Array.prototype.includes, so the exact match silently becomes a substring match.

With the names of the search-elements fixture, updateStyle('end event 10', ...) styles both end event 10 and end 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 1 and end event 10 pair already present in the fixture. Both fail before the fix, with Event_1hr2hqx wrongly included in the result.

Notes

BpmnElementsSearcher.getElementsByNames keeps its string[] signature. Widening it to string | 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.

`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`.
@tbouffard tbouffard added the bug Something isn't working label Aug 17, 2026
@sonarqubecloud

Copy link
Copy Markdown

@tbouffard
tbouffard merged commit f1b4616 into main Aug 20, 2026
9 checks passed
@tbouffard
tbouffard deleted the fix/style_by_name_substring_match branch August 20, 2026 08:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant