mirror of
https://github.com/denoland/deno.git
synced 2024-12-25 08:39:09 -05:00
Avoid textproto crashing on empty reader (denoland/deno_std#50)
Original: 9eb6aa5fd9
This commit is contained in:
parent
b5f6f97234
commit
95e378a28b
2 changed files with 10 additions and 2 deletions
|
@ -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) {
|
||||
|
|
|
@ -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");
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue