From 1d51b1649e75b8d2e8ca81c9aab08c9f119a6ab5 Mon Sep 17 00:00:00 2001 From: Aaron O'Mullan Date: Sun, 1 May 2022 19:13:05 -0700 Subject: fix(runtime): lossy utf8 readTextFile (#14456) --- cli/tests/unit/files_test.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'cli/tests/unit/files_test.ts') diff --git a/cli/tests/unit/files_test.ts b/cli/tests/unit/files_test.ts index a509672c0..d15f1f538 100644 --- a/cli/tests/unit/files_test.ts +++ b/cli/tests/unit/files_test.ts @@ -791,3 +791,19 @@ Deno.test( assertEquals(res, "hello world!"); }, ); + +Deno.test( + { permissions: { read: true, write: true } }, + async function readTextFileNonUtf8() { + const path = await Deno.makeTempFile(); + const file = await Deno.open(path, { write: true }); + await file.write(new TextEncoder().encode("hello ")); + await file.write(new Uint8Array([0xC0])); + file.close(); + + const res = await Deno.readTextFile(path); + const resSync = Deno.readTextFileSync(path); + assertEquals(res, resSync); + assertEquals(res, "hello \uFFFD"); + }, +); -- cgit v1.2.3