From 2664dacf7e0e13dc24485836e66081fb07ee1289 Mon Sep 17 00:00:00 2001 From: Ruben Bridgewater Date: Thu, 3 Oct 2019 02:38:37 +0200 Subject: util: validate formatWithOptions inspectOptions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This makes sure that the `inspectOptions` are validated. This could otherwise cause confusion. Fixes: https://github.com/nodejs/node/issues/29726 PR-URL: https://github.com/nodejs/node/pull/29824 Reviewed-By: Yongsheng Zhang Reviewed-By: James M Snell Reviewed-By: Minwoo Jung Reviewed-By: Colin Ihrig Reviewed-By: Michaƫl Zasso --- lib/internal/util/inspect.js | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'lib') diff --git a/lib/internal/util/inspect.js b/lib/internal/util/inspect.js index 39cbfd36b7..2f922f6659 100644 --- a/lib/internal/util/inspect.js +++ b/lib/internal/util/inspect.js @@ -1542,11 +1542,6 @@ function reduceToSingleString( return `${braces[0]}${ln}${join(output, `,\n${indentation} `)} ${braces[1]}`; } -function format(...args) { - return formatWithOptions(undefined, ...args); -} - - const firstErrorLine = (error) => error.message.split('\n')[0]; let CIRCULAR_ERROR_MESSAGE; function tryStringify(arg) { @@ -1569,7 +1564,19 @@ function tryStringify(arg) { } } +function format(...args) { + return formatWithOptionsInternal(undefined, ...args); +} + function formatWithOptions(inspectOptions, ...args) { + if (typeof inspectOptions !== 'object' || inspectOptions === null) { + throw new ERR_INVALID_ARG_TYPE( + 'inspectOptions', 'object', inspectOptions); + } + return formatWithOptionsInternal(inspectOptions, ...args); +} + +function formatWithOptionsInternal(inspectOptions, ...args) { const first = args[0]; let a = 0; let str = ''; -- cgit v1.2.3