Repository navigation
fix: treat an issue comment without a body as having no commands - #374
Merged
Merged
Conversation
GitHub allows an empty issue comment, whose `comment.body` arrives as null. handleIssueComment passed it straight to hasCommand, whose line splitting calls `body.replace(...)`, so the run failed with `TypeError: Cannot read properties of null (reading 'replace')`. A missing or null body is now read as the empty string: no command matches, nothing is called and the run succeeds. The handlers only run after hasCommand has matched, and /meow, the approve plugin and the comment scanners already guard their bodies, so the dispatcher is the only place the crash was reachable. Signed-off-by: Jeffrey Sica <me@jeefy.dev>
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.
Bug
GitHub allows an empty issue comment; its
comment.bodyarrives asnull.handleIssueCommentpassedcontext.payload.comment?.bodyunguarded tohasCommand, whose line splitting (commandLines→splitLines) callsbody.replace(...), so the run fails:(
... of undefined ...when the body or the comment is absent).Fix
handleIssueCommentreads a missing/null body as'': no command matches, nothing runs, the run succeeds. One-line guard, no refactor. I checked the other readers ofcomment.body: the handlers only run afterhasCommandhas matched (so the body is non-empty),/meowalready checkstypeof body === 'string', and the approve plugin / comment scanners already usebody ?? ''— the dispatcher was the only reachable crash.dist/regenerated withnpm run pack.Tests
__tests__/issueCommentTest/commentWithoutBody.test.ts, parametrized over anullbody, a comment with nobodyfield and a payload with nocomment, with nine commands configured:handleIssueCommentresolves,setFailedis not called, nofetch, and no API request (msw withfailOnUnhandledRequestplus arequest:startrecorder). All three fail onmainwith the TypeError above and pass here.npm run all(1828 tests),npm run test:coverage(100 / 99.82 / 100 / 100),npm run test:coverage:e2epass; a secondnpm run packleavesdist/clean.Note: open PR #361 pins this crash text to exercise
run()'s catch; after this lands a null body no longer throws, so that test will need to reach the catch another way.