From 95e378a28b0e0ba1d05f2a41bc27a7368aac66f4 Mon Sep 17 00:00:00 2001 From: "Kevin (Kun) \"Kassimo\" Qian" Date: Mon, 31 Dec 2018 04:00:28 -0500 Subject: [PATCH] Avoid textproto crashing on empty reader (denoland/deno_std#50) Original: https://github.com/denoland/deno_std/commit/9eb6aa5fd9da9da9cd2b96a5199cf9b9128fd456 --- net/textproto.ts | 5 +++-- net/textproto_test.ts | 7 +++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/net/textproto.ts b/net/textproto.ts index 342d74b33e..832299e1c2 100644 --- a/net/textproto.ts +++ b/net/textproto.ts @@ -118,11 +118,12 @@ export class TextProtoReader { async readLineSlice(): Promise<[Uint8Array, BufState]> { // this.closeDot(); - let line: null | Uint8Array; + let line: Uint8Array; while (true) { let [l, more, err] = await this.r.readLine(); if (err != null) { - return [null, err]; + // Go's len(typed nil) works fine, but not in JS + return [new Uint8Array(0), err]; } // Avoid the copy if the first call produced a full line. if (line == null && !more) { diff --git a/net/textproto_test.ts b/net/textproto_test.ts index ad7e6a2c41..3af21247a6 100644 --- a/net/textproto_test.ts +++ b/net/textproto_test.ts @@ -93,3 +93,10 @@ test(async function textprotoAppend() { const joined = append(u1, u2); assertEqual(dec.decode(joined), "Hello World"); }); + +test(async function textprotoReadEmpty() { + let r = reader(""); + let [m, err] = await r.readMIMEHeader(); + // Should not crash! + assertEqual(err, "EOF"); +});