mirror of https://github.com/OpenIdentityPlatform/OpenDJ.git

Jean-Noel Rouvignac
13.24.2014 6acb5680cc685afc071ca5bcc358d31690bb1786
opendj-cli/src/main/java/com/forgerock/opendj/cli/CommandBuilder.java
@@ -28,9 +28,12 @@
import static com.forgerock.opendj.cli.Utils.OBFUSCATED_VALUE;
import java.util.Arrays;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.TreeSet;
import com.forgerock.opendj.util.OperatingSystem;
@@ -188,28 +191,25 @@
            } else if (arg instanceof FileBasedArgument) {
                for (String value : ((FileBasedArgument) arg).getNameToValueMap().keySet()) {
                    builder.append(lineSeparator + argName + " ");
                    if (isObfuscated(arg) && !showObfuscated) {
                        value = OBFUSCATED_VALUE;
                    } else {
                        value = escapeValue(value);
                    }
                    builder.append(value);
                    builder.append(getOutputValue(value, arg, showObfuscated));
                }
            } else {
                for (String value : arg.getValues()) {
                    builder.append(lineSeparator + argName + " ");
                    if (isObfuscated(arg) && !showObfuscated) {
                        value = OBFUSCATED_VALUE;
                    } else {
                        value = escapeValue(value);
                    }
                    builder.append(value);
                    builder.append(getOutputValue(value, arg, showObfuscated));
                }
            }
        }
        return builder.toString();
    }
    private String getOutputValue(final String value, final Argument arg, final boolean showObfuscated) {
        if (isObfuscated(arg) && !showObfuscated) {
            return OBFUSCATED_VALUE;
        }
        return escapeValue(value);
    }
    /**
     * Clears the arguments.
     */
@@ -238,9 +238,9 @@
        return obfuscatedArgs.contains(argument);
    }
    // Chars that require special treatment when passing them to command-line.
    private final static char[] CHARSTOESCAPE =
    { ' ', '\t', '\n', '|', ';', '<', '>', '(', ')', '$', '`', '\\', '"', '\'' };
    /** Chars that require special treatment when passing them to command-line. */
    private final static Set<Character> CHARSTOESCAPE = new TreeSet<Character>(Arrays.asList(
        ' ', '\t', '\n', '|', ';', '<', '>', '(', ')', '$', '`', '\\', '"', '\''));
    /**
     * This method simply takes a value and tries to transform it (with escape or '"') characters so that it can be used
@@ -255,11 +255,7 @@
        if (OperatingSystem.isUnix()) {
            for (int i = 0; i < value.length(); i++) {
                final char c = value.charAt(i);
                boolean charToEscapeFound = false;
                for (int j = 0; j < CHARSTOESCAPE.length && !charToEscapeFound; j++) {
                    charToEscapeFound = c == CHARSTOESCAPE[j];
                }
                if (charToEscapeFound) {
                if (CHARSTOESCAPE.contains(c)) {
                    b.append('\\');
                }
                b.append(c);