deno_std icon indicating copy to clipboard operation
deno_std copied to clipboard

bug(util/format): Doesn't add length to arrays formatted with `%o` and has missing spaces

Open grian32 opened this issue 5 years ago • 2 comments

deno eval "import * as util from 'https://deno.land/[email protected]/node/util.ts';console.log(util.format('%o', [10, 11]))"

outputs

[10, 11]

while

node -e 'const util = require("util");console.log(util.format("%o", [10, 11]))'

outputs

[ 10, 11, [length]: 2 ]

grian32 avatar Sep 08 '21 19:09 grian32

Hi ! I did some analysis. util.format internally calls Deno.inspect and that is where behavior is differs from Node's util.inspect

Node util.inspect

Welcome to Node.js v17.1.0.
Type ".help" for more information.
> let a = [1, 2]
undefined
> util.inspect(a, true)
'[ 1, 2, [length]: 2 ]'
> '[ 1, 2, [length]: 2 ]'

Deno.inspect

Deno 1.15.2
exit using ctrl+d or close()
> let a = [1,2]
undefined
> Deno.inspect(a)
"[ 1, 2 ]"
> Deno.inspect(a, { showHidden: true});
"[ 1, 2 ]"

I guess we should move this bug to deno lib ?

achautha avatar Nov 24 '21 12:11 achautha

@grian32 thanks for reporting that issue. I have submitted a pr to fix this issue.

F3n67u avatar Dec 19 '21 05:12 F3n67u