console.log always evaluates '%d' in a string #1434

Closed
tomdz opened this Issue Aug 1, 2011 · 2 comments

Comments

Projects
None yet
3 participants

tomdz commented Aug 1, 2011

node
> var sys = require('sys');
> var config = [ "%d" ];
> console.log(sys.inspect(config));
[ 'NaN' ]

node version is 0.4.10 on Ubuntu (Linux nobby 2.6.38-10-generic #46-Ubuntu SMP Tue Jun 28 15:07:17 UTC 2011 x86_64 x86_64 x86_64 GNU/Linux).

Owner

bnoordhuis commented Aug 1, 2011

This hasn't anything to do with JSON, it's a 'feature' of console.log() to support sprintf-style format strings.

> console.log('%d')
NaN
> console.log('%d', 42)
42

We're compatible-ish with how browsers implement it. FF 3.6.18:

>>> console.log('%d')
%d
>>> console.log('%d', 42)
42

Let's fix that.

@koichik koichik added a commit to koichik/node that referenced this issue Aug 7, 2011

@koichik koichik Improve util.format() compatibility with browser.
Fixes #1434.
858d2cf

koichik commented Aug 7, 2011

@bnoordhuis - Please review.

koichik closed this in d439c09 Aug 8, 2011

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment