0
0
mirror of https://github.com/nodejs/node.git synced 2024-11-29 23:16:30 +01:00

Add %% escape to util.format()

Fixes #1273.
This commit is contained in:
koichik 2011-07-30 22:08:59 +09:00
parent 5501a5a641
commit d3d8f1b972
2 changed files with 6 additions and 2 deletions

View File

@ -22,7 +22,7 @@
var events = require('events');
var formatRegExp = /%[sdj]/g;
var formatRegExp = /%[sdj%]/g;
exports.format = function(f) {
if (typeof f !== 'string') {
var objects = [];
@ -39,6 +39,7 @@ exports.format = function(f) {
case '%s': return String(args[i++]);
case '%d': return Number(args[i++]);
case '%j': return JSON.stringify(args[i++]);
case '%%': return '%';
default:
return x;
}

View File

@ -43,4 +43,7 @@ assert.equal(util.format('%j', 42), '42');
assert.equal(util.format('%d', '42.0'), '42');
assert.equal(util.format('%d', '42'), '42');
assert.equal(util.format('%s', '42'), '42');
assert.equal(util.format('%j', '42'), '"42"');
assert.equal(util.format('%j', '42'), '"42"');
assert.equal(util.format('%%s%s', 'foo'), '%sfoo');