diff --git a/src/org/mozilla/javascript/NativeConsole.java b/src/org/mozilla/javascript/NativeConsole.java index b4ef8e125f..2cf4a2712c 100644 --- a/src/org/mozilla/javascript/NativeConsole.java +++ b/src/org/mozilla/javascript/NativeConsole.java @@ -21,7 +21,7 @@ public class NativeConsole extends IdScriptableObject { private static final String DEFAULT_LABEL = "default"; - private static final Pattern FMT_REG = Pattern.compile("%[sfdioO%]"); + private static final Pattern FMT_REG = Pattern.compile("%[sfdioOc%]"); private final Map timers = new ConcurrentHashMap<>(); @@ -249,6 +249,9 @@ public static String format(Context cx, Scriptable scope, Object[] args) { replaceArg = formatObj(cx, scope, val); break; + // %c is not supported, + // simply removed from the output + default: replaceArg = ""; break; diff --git a/testsrc/org/mozilla/javascript/tests/NativeConsoleTest.java b/testsrc/org/mozilla/javascript/tests/NativeConsoleTest.java index 7c0d8141ee..db6060a494 100644 --- a/testsrc/org/mozilla/javascript/tests/NativeConsoleTest.java +++ b/testsrc/org/mozilla/javascript/tests/NativeConsoleTest.java @@ -253,6 +253,18 @@ public void formatObject() { } } + @Test + public void formatStyling() { + assertFormat(new Object[] {"%c", "color: orange"}, ""); + assertFormat(new Object[] {"12%c34", "color: orange"}, "1234"); + assertFormat(new Object[] {"%c", "color: orange", "color: blue"}, "color: blue"); + + // %c counts + assertFormat(new Object[] {"12%c34%s", "color: orange", "ab"}, "1234ab"); + + assertFormat(new Object[] {"%c"}, "%c"); + } + @Test public void formatValueOnly() { try (Context cx = Context.enter()) {