Fix TypeError in parseFetch for integer-shaped key tokens#1
Open
Oleksandr Hushcha (o-hushcha) wants to merge 1 commit into
Open
Fix TypeError in parseFetch for integer-shaped key tokens#1Oleksandr Hushcha (o-hushcha) wants to merge 1 commit into
Oleksandr Hushcha (o-hushcha) wants to merge 1 commit into
Conversation
Some IMAP servers emit FETCH responses where an even-indexed atom
(key position) is an integer-shaped token (e.g. "* 1 FETCH (12345 NIL)"
or as observed in the wild on the @integromat/imap consumer side via
extension/quirk responses). convStr returns a JS number for such atoms,
and parseFetch then calls .toLowerCase() on it, throwing:
TypeError: list[i].toLowerCase is not a function
at Parser.parseFetch (lib/Parser.js:431)
Coerce the key token to a string at the extraction site. Value-position
numeric atoms (RFC822.SIZE, MODSEQ, UIDNEXT, etc.) are untouched, so
existing consumers that read those as numbers see no behavior change.
Bump to 0.8.22.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Fixes a TypeError in parseFetch when a FETCH response contains an integer-shaped atom at a key position (which convStr returns as a JS number, lacking .toLowerCase).
Changes:
- Coerce the key token to a string before calling
.toLowerCase()inparseFetch. - Add a regression test for an untagged FETCH with a numeric key token.
- Bump package version to 0.8.22.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| lib/Parser.js | Wraps key token with String(...) to prevent crash on numeric atoms. |
| test/test-parser.js | New regression test covering numeric key tokens in FETCH. |
| package.json | Patch version bump to 0.8.22. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.
Summary
Fixes a
TypeError: list[i].toLowerCase is not a functionthrown fromParser.parseFetch(lib/Parser.js:431) when an IMAP server emits a FETCH response with an integer-shaped atom at a key position (e.g.* 1 FETCH (12345 NIL)).convStrreturns a JSnumberfor integer-shaped tokens (intentional, see comment at lib/Parser.js:738-740 — preserves large-int precision by falling back to string). When such a token lands at a key position,parseFetchthen calls.toLowerCase()on a number and crashes.Observed in production via
@integromat/imap@0.8.21consumed by Make's Email v7 native app (saveAfterSent: truepath; the unsolicited FETCH arrives on the persistent socket afterAPPEND). The throw is synchronous inside the parser's'readable'callback, so it bypasses caller.catchchains and surfaces as an uncaught exception.Fix
Coerce the key token to a string at the extraction site:
Narrow on purpose:
RFC822.SIZE,MODSEQ,UIDNEXT,MESSAGES, etc.) —convStr's existing int →numberbehaviour is preserved, so consumers that read those as numbers see no change. Existingtest-parser.jscases that assert'rfc822.size': 4286etc. still pass.Regression test
test/test-parser.jsgains one case:* 1 FETCH (12345 NIL)parses to{ type: 'fetch', num: 1, text: { '12345': null } }. Without this PR, the same input throws the exact production stack:Version
Bumped
0.8.21→0.8.22.Test plan
npm testpasses on the branch🤖 Generated with Claude Code
https://make.atlassian.net/browse/IEN-12427