This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

util: fix util.format() formatting of %%

  • Loading branch information...
1 parent d6f0ecc commit 578ba76e6c0e16827bf9e471bdef500aedf3b09e ssuda committed with bnoordhuis 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 578ba76

Please sign in to comment.