Permalink
Browse files

util.format fix

  • Loading branch information...
1 parent 0613af0 commit c4e4266dad7067e6b926f3b8a5258d5e98b3f918 ssuda committed Mar 2, 2012
Showing with 3 additions and 2 deletions.
  1. +1 −1 lib/util.js
  2. +2 −1 test/simple/test-util-format.js
View
@@ -33,12 +33,12 @@ exports.format = function(f) {
var args = arguments;
var len = args.length;
var str = String(f).replace(formatRegExp, function(x) {
+ if (x === '%%') return '%';
if (i >= len) return x;
switch (x) {
case '%s': return String(args[i++]);
case '%d': return Number(args[i++]);
case '%j': return JSON.stringify(args[i++]);
- case '%%': return '%';
default:
return x;
}
@@ -58,4 +58,5 @@ assert.equal(util.format('%s:%s', undefined), 'undefined:%s');
assert.equal(util.format('%s:%s', 'foo'), 'foo:%s');
assert.equal(util.format('%s:%s', 'foo', 'bar'), 'foo:bar');
assert.equal(util.format('%s:%s', 'foo', 'bar', 'baz'), 'foo:bar baz');
-
+assert.equal(util.format('%%%s%%', 'hi'), '%hi%');
+assert.equal(util.format('%%%s%%%%', 'hi'), '%hi%%');

0 comments on commit c4e4266

Please sign in to comment.