From a585c5bbb3fd02602f947890a78aee9a78439308 Mon Sep 17 00:00:00 2001 From: Dmitry Baranovskiy Date: Thu, 22 Jul 2010 21:26:55 +1000 Subject: [PATCH] =?UTF-8?q?Fixed=20format,=20so=20it=20wouldn=E2=80=99t=20?= =?UTF-8?q?blow=20up=20if=20%d=20argument=20is=20null=20or=20undefined=20+?= =?UTF-8?q?=20ensure=20that=20numbers=20will=20be=20numbers?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/node.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/node.js b/src/node.js index 914f02f6609..ff195041f49 100644 --- a/src/node.js +++ b/src/node.js @@ -190,15 +190,14 @@ process.openStdin = function () { // console object - +var formatRegExp = /%[sdj]/g; function format (f) { var i = 1; var args = arguments; - if (!(f instanceof String)) f = String(f); - return f.replace(/%([sdj])/g, function (x) { + return String(f).replace(formatRegExp, function (x) { switch (x) { case '%s': return args[i++]; - case '%d': return args[i++].toString(); + case '%d': return +args[i++]; case '%j': return JSON.stringify(args[i++]); default: return x;