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
|
// console object
|
||||||
|
var formatRegExp = /%[sdj]/g;
|
||||||
function format (f) {
|
function format (f) {
|
||||||
var i = 1;
|
var i = 1;
|
||||||
var args = arguments;
|
var args = arguments;
|
||||||
if (!(f instanceof String)) f = String(f);
|
return String(f).replace(formatRegExp, function (x) {
|
||||||
return f.replace(/%([sdj])/g, function (x) {
|
|
||||||
switch (x) {
|
switch (x) {
|
||||||
case '%s': return args[i++];
|
case '%s': return args[i++];
|
||||||
case '%d': return args[i++].toString();
|
case '%d': return +args[i++];
|
||||||
case '%j': return JSON.stringify(args[i++]);
|
case '%j': return JSON.stringify(args[i++]);
|
||||||
default:
|
default:
|
||||||
return x;
|
return x;
|
||||||
|
|
Loading…
Reference in New Issue