Skip to content

Conversation

stefanvanderwolf
Copy link
Contributor

@stefanvanderwolf stefanvanderwolf commented Sep 25, 2025

The @OnEvent decorator accepts the following types for its argument:

string | symbol | Array<string | symbol>

If a Symbol is included in an array, the code to get the eventName will throw a TypeError (String(event)) This occurs because JavaScript’s
Array.prototype.join internally calls ToString on each array element. Per the specification, ToString(Symbol) is not allowed and results in a TypeError.

To avoid this issue, do not rely on String(array) or .join() on arrays containing symbols directly. Instead, explicitly convert each element to a string while handling symbols safely.

I couldn't find a way to test adding multiple @OnEvent so the second part can be tested. It didn't have any tests before (as far as I can tell), but would be nice to add them.

doc: https://tc39.es/ecma262/multipage/indexed-collections.html#sec-array.prototype.join
doc: https://tc39.es/ecma262/multipage/abstract-operations.html#sec-tostring

The @onevent decorator accepts the following types for its argument:

```typescript
string | symbol | Array<string | symbol>
``

If a Symbol is included in an array, the code to get the eventName will
throw a TypeError (String(event)) This occurs because JavaScript’s
Array.prototype.join internally calls ToString on each array element.
Per the specification, ToString(Symbol) is not allowed and results in a
TypeError.

To avoid this issue, do not rely on String(array) or .join() on arrays
containing symbols directly. Instead, explicitly convert each element to
a string while handling symbols safely.

doc: https://tc39.es/ecma262/multipage/indexed-collections.html#sec-array.prototype.join
doc: https://tc39.es/ecma262/multipage/abstract-operations.html#sec-tostring
} else if (Array.isArray(event)) {
return event.map(eventNameFromEvent).join(',');
} else return String(event);
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Symbol Handling Fails in Event Name Extraction

The eventNameFromEvent function at line 82 uses String(event) in its fallback, which throws a TypeError when the event is a Symbol. This prevents proper Symbol handling, contrary to the PR's intent.

Fix in Cursor Fix in Web

Copy link
Contributor Author

@stefanvanderwolf stefanvanderwolf Sep 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@s1gr1d s1gr1d requested a review from chargome September 25, 2025 14:10
@chargome chargome self-assigned this Oct 3, 2025
Copy link
Member

@chargome chargome left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense to me, thanks for contributing this!

@chargome chargome merged commit a266909 into getsentry:develop Oct 6, 2025
41 checks passed
chargome added a commit that referenced this pull request Oct 6, 2025
This PR adds the external contributor to the CHANGELOG.md file, so that
they are credited for their contribution. See #17785

Co-authored-by: chargome <[email protected]>
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.

2 participants