From 9b5e9f7ef28d19b2816c68053c110f9dfdf5116e Mon Sep 17 00:00:00 2001 From: Nathan Rajlich Date: Sun, 1 Jun 2014 10:26:58 -0700 Subject: [PATCH] browser: even more robust "%c" handling Now we support the user passing in their own "%c" fields in `debug()` calls. --- browser.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/browser.js b/browser.js index 38f83ea..cef8ea5 100644 --- a/browser.js +++ b/browser.js @@ -91,14 +91,18 @@ function log() { // arguments passed either before or after the %c, so we need to // figure out the correct index to insert the CSS into var index = 0; + var lastC = 0; args[0].replace(/%[a-z%]/g, function(match) { if ('%%' === match) return; index++; - if (index < 3) return; // skip the first 2 %c's since that's handled already if ('%c' === match) { - args.splice(index, 0, c); + // we only are interested in the *last* %c + // (the user may have provided their own) + lastC = index; } }); + + args.splice(lastC, 0, c); } // This hackery is required for IE8,