From 3af23c31dd563dee90c8e44071a5fde5e1caabfe Mon Sep 17 00:00:00 2001
From: Richard Gibson <richard.gibson@gmail.com>
Date: Tue, 5 Oct 2021 20:23:44 -0400
Subject: [PATCH] Support UTF-8 decoding for non-buffer input

Fixes #2081
---
 bits/40_harb.js | 1 +
 1 file changed, 1 insertion(+)

diff --git a/bits/40_harb.js b/bits/40_harb.js
index 0892781..c417edf 100644
--- a/bits/40_harb.js
+++ b/bits/40_harb.js
@@ -940,6 +940,7 @@ var PRN = (function() {
 			default: throw new Error("Unrecognized type " + opts.type);
 		}
 		if(bytes[0] == 0xEF && bytes[1] == 0xBB && bytes[2] == 0xBF) str = utf8read(str.slice(3));
+		else if(opts.type != 'string' && opts.codepage == 65001) str = utf8read(str);
 		else if((opts.type == 'binary') && typeof cptable !== 'undefined' && opts.codepage)  str = cptable.utils.decode(opts.codepage, cptable.utils.encode(28591,str));
 		if(str.slice(0,19) == "socialcalc:version:") return ETH.to_sheet(opts.type == 'string' ? str : utf8read(str), opts);
 		return prn_to_sheet_str(str, opts);