fix: potential null dereference in formatEmojiCreatorList when emojis[0] is undefined#5711
Conversation
|
@zendy199x is attempting to deploy a commit to the Rocicorp Team on Vercel. A member of the Team first needs to authorize it. |
There was a problem hiding this comment.
Pull request overview
This PR aims to prevent a runtime error in apps/zbugs emoji tooltip formatting by guarding against empty emoji lists before reading emojis[0].annotation.
Changes:
- Add an early return in
formatEmojiTooltipTextwhenemojis.length === 0. - Add a new
tests/emoji-utils.test.tsfile with unit tests for several emoji utility helpers.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 6 comments.
| File | Description |
|---|---|
| apps/zbugs/src/emoji-utils.ts | Adds an empty-list guard in tooltip formatting to avoid accessing emojis[0] when there are no emojis. |
| tests/emoji-utils.test.ts | Adds new tests for emoji utility functions, but currently appears misplaced and inconsistent with repo test/type conventions. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
848a89f to
feb5434
Compare
|
It is an error to call We could change the TS type from |
…icreatorli Signed-off-by: Zendy <50132805+zendy199x@users.noreply.github.com>
66caa23 to
004504c
Compare
|
No code change in this pass for "It is an error to call |
Summary
The function
formatEmojiTooltipTextcallsemojis[0].annotationwithout checking ifemojisis empty or ifemojis[0]exists. Ifemojisis empty, this will throw a runtime error. AlthoughformatEmojiCreatorListhas an assertion thatemojis.length > 0,formatEmojiTooltipTextdoesn't validate this before accessingemojis[0].Changes
apps/zbugs/src/emoji-utils.tsAdd a check in
formatEmojiTooltipTextto ensureemojisis not empty before accessingemojis[0]. For example:if (emojis.length === 0) return '';Testing