Skip to content

fix: potential null dereference in formatEmojiCreatorList when emojis[0] is undefined#5711

Open
zendy199x wants to merge 1 commit intorocicorp:mainfrom
zendy199x:fix/potential-null-dereference-in-formatemojicreatorli
Open

fix: potential null dereference in formatEmojiCreatorList when emojis[0] is undefined#5711
zendy199x wants to merge 1 commit intorocicorp:mainfrom
zendy199x:fix/potential-null-dereference-in-formatemojicreatorli

Conversation

@zendy199x
Copy link
Copy Markdown

Summary

The function formatEmojiTooltipText calls emojis[0].annotation without checking if emojis is empty or if emojis[0] exists. If emojis is empty, this will throw a runtime error. Although formatEmojiCreatorList has an assertion that emojis.length > 0, formatEmojiTooltipText doesn't validate this before accessing emojis[0].

Changes

  • apps/zbugs/src/emoji-utils.ts

Add a check in formatEmojiTooltipText to ensure emojis is not empty before accessing emojis[0]. For example: if (emojis.length === 0) return '';

Testing

  • Verified changes follow existing project conventions
  • Confirmed no regressions in affected code paths

Copilot AI review requested due to automatic review settings March 28, 2026 14:19
@vercel
Copy link
Copy Markdown

vercel Bot commented Mar 28, 2026

@zendy199x is attempting to deploy a commit to the Rocicorp Team on Vercel.

A member of the Team first needs to authorize it.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 formatEmojiTooltipText when emojis.length === 0.
  • Add a new tests/emoji-utils.test.ts file 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.

Comment thread tests/emoji-utils.test.ts
Comment thread tests/emoji-utils.test.ts
Comment thread apps/zbugs/src/emoji-utils.ts
Comment thread apps/zbugs/src/emoji-utils.ts
Comment thread tests/emoji-utils.test.ts
Comment thread tests/emoji-utils.test.ts
@zendy199x zendy199x force-pushed the fix/potential-null-dereference-in-formatemojicreatorli branch 4 times, most recently from 848a89f to feb5434 Compare March 30, 2026 08:21
@arv
Copy link
Copy Markdown
Contributor

arv commented Mar 31, 2026

It is an error to call formatEmojiTooltipText with an empty array. That is what the assert is about.

We could change the TS type from T[] to [T, ...rest: T[]]. Then we will have to check the caller but the caller should be clear that we can never have an empty array.

…icreatorli

Signed-off-by: Zendy <50132805+zendy199x@users.noreply.github.com>
@zendy199x zendy199x force-pushed the fix/potential-null-dereference-in-formatemojicreatorli branch from 66caa23 to 004504c Compare April 2, 2026 16:58
@zendy199x
Copy link
Copy Markdown
Author

No code change in this pass for "It is an error to call formatEmojiTooltipText with an empty array. That is..." based on the current diff because I could not map this comment to a concrete file path safely. The thread remains open for maintainer direction.

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.

3 participants