mirror of https://github.com/nodejs/node.git
Fixed format, so it wouldn’t blow up if %d argument is null or undefined + ensure that numbers will be numbers
parent
2c1ca4078d
commit
a585c5bbb3
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue