File tree Expand file tree Collapse file tree 2 files changed +8
-5
lines changed
json-path/src/main/java/com/jayway/jsonpath/internal/path Expand file tree Collapse file tree 2 files changed +8
-5
lines changed Original file line number Diff line number Diff line change 66import java .util .ArrayList ;
77import java .util .Collections ;
88import java .util .List ;
9+ import java .util .regex .Pattern ;
910
1011import static java .lang .Character .isDigit ;
1112
1213public class ArrayIndexOperation {
1314
15+ private final static Pattern COMMA = Pattern .compile ("\\ s*,\\ s*" );
16+
1417 private final List <Integer > indexes ;
1518
1619 private ArrayIndexOperation (List <Integer > indexes ) {
@@ -39,13 +42,13 @@ public static ArrayIndexOperation parse(String operation) {
3942 //check valid chars
4043 for (int i = 0 ; i < operation .length (); i ++) {
4144 char c = operation .charAt (i );
42- if (!isDigit (c ) && c != ',' ) {
45+ if (!isDigit (c ) && c != ',' && c != ' ' ) {
4346 throw new InvalidPathException ("Failed to parse ArrayIndexOperation: " + operation );
4447 }
4548 }
46- String [] tokens = operation .split ("," );
49+ String [] tokens = COMMA .split (operation , - 1 );
4750
48- List <Integer > tempIndexes = new ArrayList <Integer >();
51+ List <Integer > tempIndexes = new ArrayList <Integer >(tokens . length );
4952 for (String token : tokens ) {
5053 tempIndexes .add (parseInteger (token ));
5154 }
Original file line number Diff line number Diff line change @@ -512,7 +512,7 @@ private boolean readArrayToken(PathTokenAppender appender) {
512512 return false ;
513513 }
514514
515- String expression = path .subSequence (expressionBeginIndex , expressionEndIndex ).toString ().replace ( " " , "" );
515+ String expression = path .subSequence (expressionBeginIndex , expressionEndIndex ).toString ().trim ( );
516516
517517 if ("*" .equals (expression )) {
518518 return false ;
@@ -521,7 +521,7 @@ private boolean readArrayToken(PathTokenAppender appender) {
521521 //check valid chars
522522 for (int i = 0 ; i < expression .length (); i ++) {
523523 char c = expression .charAt (i );
524- if (!isDigit (c ) && c != COMMA && c != MINUS && c != SPLIT ) {
524+ if (!isDigit (c ) && c != COMMA && c != MINUS && c != SPLIT && c != SPACE ) {
525525 return false ;
526526 }
527527 }
You can’t perform that action at this time.
0 commit comments