From fcdf631736a21188426fc4abd1b2b8d0ca0c7cc3 Mon Sep 17 00:00:00 2001 From: Vyacheslav Moklev Date: Wed, 20 Nov 2019 16:32:00 +0300 Subject: [PATCH] Fix suggestions from IDEA-CR-55562 review GitOrigin-RevId: c8c530588d652c4f8f08d97af96bc1b6cefd25de --- .../process/impl/ProcessListUtil.java | 31 +++++++------------ 1 file changed, 11 insertions(+), 20 deletions(-) diff --git a/platform/platform-util-io/src/com/intellij/execution/process/impl/ProcessListUtil.java b/platform/platform-util-io/src/com/intellij/execution/process/impl/ProcessListUtil.java index 174d13ab3056..067246544503 100644 --- a/platform/platform-util-io/src/com/intellij/execution/process/impl/ProcessListUtil.java +++ b/platform/platform-util-io/src/com/intellij/execution/process/impl/ProcessListUtil.java @@ -266,18 +266,18 @@ public final class ProcessListUtil { return parseCommandOutput(Collections.singletonList(exeFile.getAbsolutePath()), ProcessListUtil::parseWinProcessListHelperOutput); } - @Nullable + @NotNull private static String unescapeString(String str, boolean quoted) { StringBuilder builder = new StringBuilder(); - if (quoted) { - str = str.substring(1, str.length() - 1); - } - for (int index = 0; index < str.length(); index++) { + int start = quoted ? 1 : 0; + int end = quoted ? str.length() - 1 : str.length(); + for (int index = start; index < end; index++) { if (str.charAt(index) == '\\') { - if (index == str.length() - 1) { - LOG.info("Invalid escaped string: backslash at the last position"); + if (index == end - 1) { + LOG.warn("Invalid escaped string: backslash at the last position"); LOG.debug(str); - return null; + builder.append('\\'); + continue; } switch (str.charAt(index + 1)) { case '\\': { @@ -293,9 +293,10 @@ public final class ProcessListUtil { break; } default: { - LOG.info("Invalid character after an escape symbol: " + str.charAt(index + 1)); + LOG.warn("Invalid character after an escape symbol: " + str.charAt(index + 1)); LOG.debug(str); - return null; + builder.append(str.charAt(index + 1)); + break; } } index++; @@ -327,19 +328,9 @@ public final class ProcessListUtil { if (id == 0) continue; String name = unescapeString(lines[offset + 1], false); - if (name == null) { - LOG.info("Invalid escaped name: " + lines[offset + 1]); - LOG.debug(output); - return null; - } if (StringUtil.isEmpty(name)) continue; String commandLine = unescapeString(lines[offset + 2], true); - if (commandLine == null) { - LOG.info("Invalid escaped command line: " + lines[offset + 2]); - LOG.debug(output); - return null; - } String args; if (commandLine.isEmpty()) { commandLine = name;