Skip to content

Commit

Permalink
Replace \n in console output with real line break
Browse files Browse the repository at this point in the history
  • Loading branch information
rbri committed Dec 23, 2022
1 parent 33f6d5e commit e5adee7
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
9 changes: 9 additions & 0 deletions src/changes/changes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,15 @@

<body>
<release version="2.68.0" date="Dezember xx, 2022" description="Chrome/Edge 108, Firefox 108, Bugfixes, neko-html without xerces">
<action type="fix" dev="rbri">
Replace \n in console output with real line break.
</action>
<action type="fix" dev="rbri">
core-js: Make sure the placeholder replacements of console.log() is also done for ConsStrings.
</action>
<action type="fix" dev="rbri">
core-js: console.log() ignores %c styling but updates the param count to not disturb further replacements.
</action>
<action type="add" dev="rbri" issue="535">
Support for unicode point escapes added when converting regex from js to java.
</action>
Expand Down
16 changes: 11 additions & 5 deletions src/main/java/com/gargoylesoftware/htmlunit/WebConsole.java
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ public void print(final Context cx, final Scriptable scope, final Level level,
switch (level) {
case TRACE:
if (logger_.isInfoEnabled()) {
String msg = NativeConsole.format(cx, scope, args);
String msg = format(cx, scope, args);
if (stack != null) {
final StringBuilder scriptStack = new StringBuilder();
scriptStack.append(msg);
Expand All @@ -179,22 +179,22 @@ public void print(final Context cx, final Scriptable scope, final Level level,
break;
case DEBUG:
if (logger_.isDebugEnabled()) {
logger_.debug(NativeConsole.format(cx, scope, args));
logger_.debug(format(cx, scope, args));
}
break;
case INFO:
if (logger_.isInfoEnabled()) {
logger_.info(NativeConsole.format(cx, scope, args));
logger_.info(format(cx, scope, args));
}
break;
case WARN:
if (logger_.isWarnEnabled()) {
logger_.warn(NativeConsole.format(cx, scope, args));
logger_.warn(format(cx, scope, args));
}
break;
case ERROR:
if (logger_.isErrorEnabled()) {
logger_.error(NativeConsole.format(cx, scope, args));
logger_.error(format(cx, scope, args));
}
break;

Expand All @@ -203,6 +203,12 @@ public void print(final Context cx, final Scriptable scope, final Level level,
}
}

private String format(final Context cx, final Scriptable scope, final Object[] args) {
String msg = NativeConsole.format(cx, scope, args);
msg = msg.replaceAll("\\r?\\n", "\n");
return msg;
}

/**
* This class is the default logger used by WebConsole.
*/
Expand Down

0 comments on commit e5adee7

Please sign in to comment.