diff --git a/packages/utils/src/display.ts b/packages/utils/src/display.ts index 7c1aebc9d..574da5667 100644 --- a/packages/utils/src/display.ts +++ b/packages/utils/src/display.ts @@ -177,6 +177,9 @@ function baseFormat(args: unknown[], options: FormatOptions = {}): string { if (typeof value === 'bigint') { return `${value.toString()}n` } + if (typeof value === 'symbol') { + return 'NaN' + } return Number(value).toString() } case '%i': { @@ -221,7 +224,7 @@ function baseFormat(args: unknown[], options: FormatOptions = {}): string { for (let x = args[i]; i < len; x = args[++i]) { if (x === null || typeof x !== 'object') { - str += ` ${x}` + str += ` ${typeof x === 'symbol' ? x.toString() : x}` } else { str += ` ${formatArg(x)}` diff --git a/test/core/test/utils-display.spec.ts b/test/core/test/utils-display.spec.ts index 326082eee..d538edd07 100644 --- a/test/core/test/utils-display.spec.ts +++ b/test/core/test/utils-display.spec.ts @@ -27,33 +27,39 @@ describe('format', () => { } })('string value'), ], + ['%s', Symbol('test')], ['%d', 100], ['%d', 100n], ['%d', null], ['%d', {}], ['%d', {}, 'next'], + ['%d', Symbol('test')], ['%i', 100], ['%i', 100n], ['%i', null], ['%i', {}], ['%i', {}, 'next'], + ['%i', Symbol('test')], ['%f', 100], ['%f', 100n], ['%f', null], ['%f', {}], ['%f', {}, 'next'], + ['%f', Symbol('test')], ['%o', 'string'], ['%o', 100], ['%o', 100n], ['%o', null], ['%o', {}], ['%o', {}, 'next'], + ['%o', Symbol('test')], ['%O', 'string'], ['%O', 100], ['%O', 100n], ['%O', null], ['%O', {}], ['%O', {}, 'next'], + ['%O', Symbol('test')], ['%c', 'css value'], ['%c', 'css value', 'some other value'], ['%c %f', 'css value', '100.00'], @@ -64,7 +70,9 @@ describe('format', () => { ['%j', {}, 'next'], ['%j', { obj }], ['%j', { fn: () => {} }], + ['%j', Symbol('test')], ['%%', 'string'], + ['prefix', Symbol('test')], ])('format(%s)', (formatString, ...args) => { expect(format(formatString, ...args), `failed ${formatString}`).toBe(util.format(formatString, ...args)) })