Skip to content

Commit

Permalink
Disable ANSI formatting for security autoconfiguration on Windows cmd…
Browse files Browse the repository at this point in the history
… line (elastic#83326)

In order to display formatted (bolded) autoconfiguration text on
Windows cmd prompt using JANSI, one needs to invoke the
SetConsoleMode Kernel32 API, via JANSI's AnsiConsole#install.
But we lack the testing infra to properly assert the formatting behavior,
so this PR disables ANSI-formatted output on Windows cmd prompt.

Fixes: elastic#83316
  • Loading branch information
albertzaharovits authored Jan 31, 2022
1 parent 4bf3068 commit 035fdd8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,11 @@ public ConsoleLoader.Console get() {
// package-private for tests
static @Nullable ConsoleLoader.Console newConsole(AnsiPrintStream out) {
if (isValidConsole(out)) {
return new ConsoleLoader.Console(out, () -> out.getTerminalWidth(), Ansi.isEnabled(), tryExtractPrintCharset(out));
// virtual terminal does support ANSI escape sequences, but the JVM must toggle a mode
// option on the console using the Kernel32 API, which JANSI knows to do, but ES currently lacks
// the testing infra to assert the behavior
boolean ansiEnabled = Ansi.isEnabled() && out.getType() != AnsiType.VirtualTerminal;
return new ConsoleLoader.Console(out, () -> out.getTerminalWidth(), ansiEnabled, tryExtractPrintCharset(out));
} else {
return null;
}
Expand Down
5 changes: 5 additions & 0 deletions docs/changelog/83326.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pr: 83326
summary: Disable ANSI formatting for security autoconfiguration on Windows cmd line
area: Security
type: bug
issues: []

0 comments on commit 035fdd8

Please sign in to comment.