diff --git a/http/io_test.ts b/http/io_test.ts index b9bb56f1196d5..fd41b474e391f 100644 --- a/http/io_test.ts +++ b/http/io_test.ts @@ -51,7 +51,7 @@ test("chunkedBodyReader", async () => { await dest.write(buf.subarray(0, len)); } const exp = "aaabbbbbcccccccccccdddddddddddddddddddddd"; - assertEquals(dest.toString(), exp); + assertEquals(new TextDecoder().decode(dest.bytes()), exp); }); test("chunkedBodyReader with trailers", async () => { @@ -133,7 +133,10 @@ test("writeTrailer", async () => { new Headers({ "transfer-encoding": "chunked", trailer: "deno,node" }), new Headers({ deno: "land", node: "js" }) ); - assertEquals(w.toString(), "deno: land\r\nnode: js\r\n\r\n"); + assertEquals( + new TextDecoder().decode(w.bytes()), + "deno: land\r\nnode: js\r\n\r\n" + ); }); test("writeTrailer should throw", async () => { @@ -336,7 +339,7 @@ test("writeResponse with trailer", async () => { body, trailers: () => new Headers({ deno: "land", node: "js" }), }); - const ret = w.toString(); + const ret = new TextDecoder().decode(w.bytes()); const exp = [ "HTTP/1.1 200 OK", "transfer-encoding: chunked", diff --git a/http/server_test.ts b/http/server_test.ts index 4e7b4b69e588a..03256dd25ca64 100644 --- a/http/server_test.ts +++ b/http/server_test.ts @@ -63,7 +63,7 @@ test("responseWrite", async function (): Promise { request.conn = mockConn(); await request.respond(testCase.response); - assertEquals(buf.toString(), testCase.raw); + assertEquals(new TextDecoder().decode(buf.bytes()), testCase.raw); await request.done; } }); diff --git a/io/ioutil_test.ts b/io/ioutil_test.ts index 1f552d0e6d2d3..cf8eaf43739b4 100644 --- a/io/ioutil_test.ts +++ b/io/ioutil_test.ts @@ -76,7 +76,7 @@ Deno.test("testCopyN1", async function (): Promise { const r = stringsReader("abcdefghij"); const n = await copyN(r, w, 3); assertEquals(n, 3); - assertEquals(w.toString(), "abc"); + assertEquals(new TextDecoder().decode(w.bytes()), "abc"); }); Deno.test("testCopyN2", async function (): Promise { @@ -84,7 +84,7 @@ Deno.test("testCopyN2", async function (): Promise { const r = stringsReader("abcdefghij"); const n = await copyN(r, w, 11); assertEquals(n, 10); - assertEquals(w.toString(), "abcdefghij"); + assertEquals(new TextDecoder().decode(w.bytes()), "abcdefghij"); }); Deno.test("copyNWriteAllData", async function (): Promise { diff --git a/mime/multipart.ts b/mime/multipart.ts index 48e32c65d8c26..b2ac8dcdd3afb 100644 --- a/mime/multipart.ts +++ b/mime/multipart.ts @@ -302,7 +302,7 @@ export class MultipartReader { if (maxValueBytes < 0) { throw new RangeError("message too large"); } - const value = buf.toString(); + const value = new TextDecoder().decode(buf.bytes()); valueMap.set(p.formName, value); continue; } diff --git a/ws/test.ts b/ws/test.ts index c6e74dadcb5c5..796bf3bb81ac0 100644 --- a/ws/test.ts +++ b/ws/test.ts @@ -31,7 +31,8 @@ test("[ws] read unmasked text frame", async () => { const frame = await readFrame(buf); assertEquals(frame.opcode, OpCode.TextFrame); assertEquals(frame.mask, undefined); - assertEquals(new Buffer(frame.payload).toString(), "Hello"); + const actual = new TextDecoder().decode(new Buffer(frame.payload).bytes()); + assertEquals(actual, "Hello"); assertEquals(frame.isLastFrame, true); }); @@ -57,7 +58,8 @@ test("[ws] read masked text frame", async () => { const frame = await readFrame(buf); assertEquals(frame.opcode, OpCode.TextFrame); unmask(frame.payload, frame.mask); - assertEquals(new Buffer(frame.payload).toString(), "Hello"); + const actual = new TextDecoder().decode(new Buffer(frame.payload).bytes()); + assertEquals(actual, "Hello"); assertEquals(frame.isLastFrame, true); }); @@ -72,12 +74,14 @@ test("[ws] read unmasked split text frames", async () => { assertEquals(f1.isLastFrame, false); assertEquals(f1.mask, undefined); assertEquals(f1.opcode, OpCode.TextFrame); - assertEquals(new Buffer(f1.payload).toString(), "Hel"); + const actual1 = new TextDecoder().decode(new Buffer(f1.payload).bytes()); + assertEquals(actual1, "Hel"); assertEquals(f2.isLastFrame, true); assertEquals(f2.mask, undefined); assertEquals(f2.opcode, OpCode.Continue); - assertEquals(new Buffer(f2.payload).toString(), "lo"); + const actual2 = new TextDecoder().decode(new Buffer(f2.payload).bytes()); + assertEquals(actual2, "lo"); }); test("[ws] read unmasked ping / pong frame", async () => { @@ -87,7 +91,8 @@ test("[ws] read unmasked ping / pong frame", async () => { ); const ping = await readFrame(buf); assertEquals(ping.opcode, OpCode.Ping); - assertEquals(new Buffer(ping.payload).toString(), "Hello"); + const actual1 = new TextDecoder().decode(new Buffer(ping.payload).bytes()); + assertEquals(actual1, "Hello"); // prettier-ignore const pongFrame= [0x8a, 0x85, 0x37, 0xfa, 0x21, 0x3d, 0x7f, 0x9f, 0x4d, 0x51, 0x58] const buf2 = new BufReader(new Buffer(new Uint8Array(pongFrame))); @@ -95,7 +100,8 @@ test("[ws] read unmasked ping / pong frame", async () => { assertEquals(pong.opcode, OpCode.Pong); assert(pong.mask !== undefined); unmask(pong.payload, pong.mask); - assertEquals(new Buffer(pong.payload).toString(), "Hello"); + const actual2 = new TextDecoder().decode(new Buffer(pong.payload).bytes()); + assertEquals(actual2, "Hello"); }); test("[ws] read unmasked big binary frame", async () => {