From ad161a2a57b15a809eb91f71980fc91b5130370b Mon Sep 17 00:00:00 2001 From: Ruben Bridgewater Date: Thu, 15 Feb 2018 03:26:17 +0100 Subject: [PATCH] buffer: stricter isEncoding Due to code consolidation in https://github.com/nodejs/node/pull/7207 the isEncoding function got less strict. This commit makes sure isEncoding returns false for empty strings as before the consolidation. PR-URL: https://github.com/nodejs/node/pull/18790 Refs: https://github.com/nodejs/node/pull/7207 Reviewed-By: James M Snell Reviewed-By: Benjamin Gruenbaum Reviewed-By: Matteo Collina --- lib/buffer.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/buffer.js b/lib/buffer.js index 68cebedcc97ef4..0aa9e2001bd9d7 100644 --- a/lib/buffer.js +++ b/lib/buffer.js @@ -427,7 +427,7 @@ Buffer.compare = function compare(a, b) { Buffer.isEncoding = function isEncoding(encoding) { - return typeof encoding === 'string' && + return typeof encoding === 'string' && encoding.length !== 0 && normalizeEncoding(encoding) !== undefined; }; Buffer[kIsEncodingSymbol] = Buffer.isEncoding;