jinmeiliao commented on a change in pull request #5187:
URL: https://github.com/apache/geode/pull/5187#discussion_r439097235



##########
File path: 
geode-gfsh/src/main/java/org/apache/geode/management/internal/cli/GfshParser.java
##########
@@ -123,18 +123,25 @@ else if (insideQuoteOf == c) {
 
     List<String> furtherSplitWithEquals = new ArrayList<>();
     for (String token : splitWithWhiteSpaces) {
-      // if this token has equal sign, split around the first occurrence of it
       int indexOfFirstEqual = token.indexOf('=');
-      if (indexOfFirstEqual < 0) {
+      int indexOfFirstDoubleQuote = token.indexOf('"');
+      int indexOfFirstSingleQuote = token.indexOf('\'');
+      if (indexOfFirstEqual < 0 || token.startsWith("-D")) {
         furtherSplitWithEquals.add(token);
       } else {
-        String left = token.substring(0, indexOfFirstEqual);
-        String right = token.substring(indexOfFirstEqual + 1);
-        if (left.length() > 0) {
-          furtherSplitWithEquals.add(left);
-        }
-        if (right.length() > 0) {
-          furtherSplitWithEquals.add(right);
+        if (indexOfFirstDoubleQuote == 0 || indexOfFirstSingleQuote == 0) {
+          furtherSplitWithEquals.add(token);
+        } else if ((indexOfFirstDoubleQuote < 0 && indexOfFirstSingleQuote < 0)
+            || (indexOfFirstEqual < indexOfFirstDoubleQuote)
+            || (indexOfFirstEqual < indexOfFirstSingleQuote)) {
+          String left = token.substring(0, indexOfFirstEqual);
+          String right = token.substring(indexOfFirstEqual + 1);
+          if (left.length() > 0) {
+            furtherSplitWithEquals.add(left);
+          }
+          if (right.length() > 0) {
+            furtherSplitWithEquals.add(right);
+          }
         }
       }
     }

Review comment:
       this entire for loop can be simplified to:
   
   ```
   for (String token : splitWithWhiteSpaces) {
         // do not split with "=" if this part starts with quotes or is part of 
-D
         if(token.startsWith("'") || token.startsWith("\"") || 
token.startsWith("-D")) {
           furtherSplitWithEquals.add(token);
           continue;
         }
         // if this token has equal sign, split around the first occurrence of 
it
         int indexOfFirstEqual = token.indexOf('=');
         if (indexOfFirstEqual < 0) {
           furtherSplitWithEquals.add(token);
           continue;
         }
         String left = token.substring(0, indexOfFirstEqual);
         String right = token.substring(indexOfFirstEqual + 1);
         if (left.length() > 0) {
           furtherSplitWithEquals.add(left);
         }
         if (right.length() > 0) {
           furtherSplitWithEquals.add(right);
         }
       }
   ```




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to