浏览代码

Disable ANSI formatting for security autoconfiguration on Windows cmd line (#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: #83316
Albert Zaharovits 3 年之前
父节点
当前提交
035fdd895d

+ 5 - 1
distribution/tools/ansi-console/src/main/java/org/elasticsearch/io/ansi/AnsiConsoleLoader.java

@@ -40,7 +40,11 @@ public class AnsiConsoleLoader implements Supplier<ConsoleLoader.Console> {
     // package-private for tests
     // package-private for tests
     static @Nullable ConsoleLoader.Console newConsole(AnsiPrintStream out) {
     static @Nullable ConsoleLoader.Console newConsole(AnsiPrintStream out) {
         if (isValidConsole(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 {
         } else {
             return null;
             return null;
         }
         }

+ 5 - 0
docs/changelog/83326.yaml

@@ -0,0 +1,5 @@
+pr: 83326
+summary: Disable ANSI formatting for security autoconfiguration on Windows cmd line
+area: Security
+type: bug
+issues: []