GEODE-3054: escaping the escape character in the command string before passing it to the SimpleParser
Project: http://git-wip-us.apache.org/repos/asf/geode/repo Commit: http://git-wip-us.apache.org/repos/asf/geode/commit/2579a0db Tree: http://git-wip-us.apache.org/repos/asf/geode/tree/2579a0db Diff: http://git-wip-us.apache.org/repos/asf/geode/diff/2579a0db Branch: refs/heads/feature/GEM-1483 Commit: 2579a0db0f9e1acad55d3be8dd3a3d5bb33f32d5 Parents: 0211029 Author: Jinmei Liao <jil...@pivotal.io> Authored: Thu Jun 8 11:08:03 2017 -0700 Committer: Jinmei Liao <jil...@pivotal.io> Committed: Fri Jun 9 10:42:03 2017 -0700 ---------------------------------------------------------------------- .../management/internal/cli/GfshParser.java | 2 + .../internal/cli/MultipleValueAdapter.java | 35 ------------- .../internal/cli/MultipleValueConverter.java | 55 -------------------- .../internal/cli/GfshParserParsingTest.java | 29 +++++++++++ 4 files changed, 31 insertions(+), 90 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/geode/blob/2579a0db/geode-core/src/main/java/org/apache/geode/management/internal/cli/GfshParser.java ---------------------------------------------------------------------- diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/GfshParser.java b/geode-core/src/main/java/org/apache/geode/management/internal/cli/GfshParser.java index df16e9b..b5c24cb 100755 --- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/GfshParser.java +++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/GfshParser.java @@ -177,6 +177,8 @@ public class GfshParser extends SimpleParser { public GfshParseResult parse(String userInput) { String rawInput = convertToSimpleParserInput(userInput); + // this tells the simpleParser not to interpret backslash as escaping character + rawInput = rawInput.replace("\\", "\\\\"); // User SimpleParser to parse the input ParseResult result = super.parse(rawInput); http://git-wip-us.apache.org/repos/asf/geode/blob/2579a0db/geode-core/src/main/java/org/apache/geode/management/internal/cli/MultipleValueAdapter.java ---------------------------------------------------------------------- diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/MultipleValueAdapter.java b/geode-core/src/main/java/org/apache/geode/management/internal/cli/MultipleValueAdapter.java deleted file mode 100644 index 5c466a0..0000000 --- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/MultipleValueAdapter.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more contributor license - * agreements. See the NOTICE file distributed with this work for additional information regarding - * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the License. You may obtain a - * copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License - * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express - * or implied. See the License for the specific language governing permissions and limitations under - * the License. - */ -package org.apache.geode.management.internal.cli; - -import java.util.List; - -import org.springframework.shell.core.Completion; -import org.springframework.shell.core.MethodTarget; - -public abstract class MultipleValueAdapter<T> implements MultipleValueConverter<T> { - - @Override - public T convertFromText(String value, Class<?> targetType, String optionContext) { - return null; - } - - @Override - public boolean getAllPossibleValues(List<Completion> completions, Class<?> targetType, - String existingData, String optionContext, MethodTarget target) { - return false; - } - -} http://git-wip-us.apache.org/repos/asf/geode/blob/2579a0db/geode-core/src/main/java/org/apache/geode/management/internal/cli/MultipleValueConverter.java ---------------------------------------------------------------------- diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/MultipleValueConverter.java b/geode-core/src/main/java/org/apache/geode/management/internal/cli/MultipleValueConverter.java deleted file mode 100644 index e3e1fec..0000000 --- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/MultipleValueConverter.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more contributor license - * agreements. See the NOTICE file distributed with this work for additional information regarding - * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the License. You may obtain a - * copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License - * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express - * or implied. See the License for the specific language governing permissions and limitations under - * the License. - */ -package org.apache.geode.management.internal.cli; - -import java.util.List; - -import org.springframework.shell.core.Completion; -import org.springframework.shell.core.Converter; -import org.springframework.shell.core.MethodTarget; - -/** - * Extends {@link Converter} to add multiple value support - * - * - * @param <T> - */ -public interface MultipleValueConverter<T> extends Converter<T> { - - /** - * Similar to {@link Converter#convertFromText(String, Class, String)} but with support for - * multiple values - * - * @param value - * @param targetType - * @param context - * @return required Data - */ - T convertFromText(String[] value, Class<?> targetType, String context); - - /** - * Similar to {@link Converter#getAllPossibleValues(List, Class, String, String, MethodTarget)} - * but with support for multiple values - * - * @param completions - * @param targetType - * @param existingData - * @param context - * @param target - * @return required Data - */ - boolean getAllPossibleValues(List<Completion> completions, Class<?> targetType, - String[] existingData, String context, MethodTarget target); -} http://git-wip-us.apache.org/repos/asf/geode/blob/2579a0db/geode-core/src/test/java/org/apache/geode/management/internal/cli/GfshParserParsingTest.java ---------------------------------------------------------------------- diff --git a/geode-core/src/test/java/org/apache/geode/management/internal/cli/GfshParserParsingTest.java b/geode-core/src/test/java/org/apache/geode/management/internal/cli/GfshParserParsingTest.java index ab6dc3d..a2efb36 100644 --- a/geode-core/src/test/java/org/apache/geode/management/internal/cli/GfshParserParsingTest.java +++ b/geode-core/src/test/java/org/apache/geode/management/internal/cli/GfshParserParsingTest.java @@ -262,4 +262,33 @@ public class GfshParserParsingTest { assertThat(result).isNotNull(); } + + @Test + public void testCommandWithBackSlash() throws Exception { + String command = + "describe offline-disk-store --name=testDiskStore --disk-dirs=R:\\regrResults\\test"; + GfshParseResult result = parser.parse(command); + assertThat(result.getParamValue("disk-dirs")).isEqualTo("R:\\regrResults\\test"); + } + + @Test + public void testCommandWithBackSlashTwo() throws Exception { + String command = "start locator --name=\\test"; + GfshParseResult result = parser.parse(command); + assertThat(result.getParamValue("name")).isEqualTo("\\test"); + } + + @Test + public void testCommandWithBackSlashThree() throws Exception { + String command = "start locator --name=\\myName"; + GfshParseResult result = parser.parse(command); + assertThat(result.getParamValue("name")).isEqualTo("\\myName"); + } + + @Test + public void testCommandWithBackSlashFour() throws Exception { + String command = "start locator --name=\\u0005Name"; + GfshParseResult result = parser.parse(command); + assertThat(result.getParamValue("name")).isEqualTo("\\u0005Name"); + } }