Skip to content

Commit a4944f4

Browse files
fix: keep surrogate numeric character references from failing the mail list (#183)
Signed-off-by: Charan Rathore <180254320+charan-rathore@users.noreply.github.com>
1 parent 0585a69 commit a4944f4

2 files changed

Lines changed: 17 additions & 1 deletion

File tree

‎packages/integrations/src/google.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,10 @@ function decodeSnippet(value: string): string {
188188
entity[1].toLowerCase() === "x"
189189
? Number.parseInt(entity.slice(2), 16)
190190
: Number.parseInt(entity.slice(1), 10);
191-
return code >= 0 && code <= 0x10ffff ? String.fromCodePoint(code) : original;
191+
// Surrogates are not scalar values: fromCodePoint throws on them, and one
192+
// such reference in a snippet must not reject the whole message list.
193+
const scalar = code >= 0 && code <= 0x10ffff && !(code >= 0xd800 && code <= 0xdfff);
194+
return scalar ? String.fromCodePoint(code) : original;
192195
},
193196
);
194197
}

‎tests/google.test.ts‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,19 @@ test("header decoding preserves spaces encoded inside words and next to plain te
221221
assert.equal((await client.getThread("thread1"))[0].subject, "Re: Visit résumé notes");
222222
});
223223

224+
test("a numeric character reference to a surrogate stays literal instead of failing the list", async () => {
225+
// String.fromCodePoint throws on surrogate code points; a sender can put the
226+
// literal text &#xD800; in a snippet, and one such message must not reject
227+
// the whole list (Promise.all over per-message parses).
228+
const client = clientWith((request) =>
229+
new URL(request.url).pathname.endsWith("/messages")
230+
? json({ messages: [{ id: "msg1" }] })
231+
: json({ id: "msg1", threadId: "thread1", snippet: "Entity notes: &#xD800; and &#55296;" }),
232+
);
233+
const [mail] = await client.listMail();
234+
assert.equal(mail.body, "Entity notes: &#xD800; and &#55296;");
235+
});
236+
224237
test("a body charset TextDecoder does not know falls back to UTF-8 instead of failing the list", async () => {
225238
const charsets: Record<string, string> = { known: "utf-8", unknown: "unknown-8bit" };
226239
const bodies: Record<string, string> = { known: "Opening hours", unknown: "Café tickets" };

0 commit comments

Comments
 (0)