Skip to content

Fix TypeError in parseFetch for integer-shaped key tokens#1

Open
Oleksandr Hushcha (o-hushcha) wants to merge 1 commit into
integromat:masterfrom
o-hushcha:fix/parser-convstr-numeric-key
Open

Fix TypeError in parseFetch for integer-shaped key tokens#1
Oleksandr Hushcha (o-hushcha) wants to merge 1 commit into
integromat:masterfrom
o-hushcha:fix/parser-convstr-numeric-key

Conversation

@o-hushcha

@o-hushcha Oleksandr Hushcha (o-hushcha) commented May 26, 2026

Copy link
Copy Markdown

Summary

Fixes a TypeError: list[i].toLowerCase is not a function thrown from Parser.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)).

convStr returns a JS number for 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, parseFetch then calls .toLowerCase() on a number and crashes.

Observed in production via @integromat/imap@0.8.21 consumed by Make's Email v7 native app (saveAfterSent: true path; the unsolicited FETCH arrives on the persistent socket after APPEND). The throw is synchronous inside the parser's 'readable' callback, so it bypasses caller .catch chains and surfaces as an uncaught exception.

Fix

Coerce the key token to a string at the extraction site:

-    key = list[i].toLowerCase();
+    key = String(list[i]).toLowerCase();

Narrow on purpose:

  • Value-position numeric atoms are untouched (RFC822.SIZE, MODSEQ, UIDNEXT, MESSAGES, etc.) — convStr's existing int → number behaviour is preserved, so consumers that read those as numbers see no change. Existing test-parser.js cases that assert 'rfc822.size': 4286 etc. still pass.
  • Defensive against any non-string at key position, not just numbers (covers arrays / NIL too, should those ever appear).

Regression test

test/test-parser.js gains 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:

TypeError: list[i].toLowerCase is not a function
    at Parser.parseFetch (lib/Parser.js:431:19)
    at Parser._resUntagged (lib/Parser.js:257:24)
    at Parser._parse (lib/Parser.js:137:16)

Version

Bumped 0.8.210.8.22.

Test plan

  • npm test passes on the branch
  • Verified the new regression case fails without the fix (exact production stack-trace match) and passes with it
  • Reviewer verifies locally against a real Make instance scenario that triggers the unsolicited FETCH

🤖 Generated with Claude Code

https://make.atlassian.net/browse/IEN-12427

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>
Copilot AI review requested due to automatic review settings May 26, 2026 21:45

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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() in parseFetch.
  • 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.

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