@@ -184,7 +184,7 @@ public final class StepDefinition {
184184 private List <Pair <Pattern , Function <String ,Object >>> objectMatcherConverters = new ArrayList <Pair <Pattern , Function <String ,Object >>>() {{
185185 // expects json so that should port to the Gremlin script form - replace curly json braces with square ones
186186 // for Gremlin sake.
187- add (Pair .with (Pattern .compile ("m\\ [(.*)\\ ]" ), s -> {
187+ add (Pair .with (Pattern .compile ("^ m\\ [(.*)\\ ]$ " ), s -> {
188188 try {
189189 // read tree from JSON - can't parse right to Map as each m[] level needs to be managed individually
190190 return convertToObject (mapper .readTree (s ));
@@ -193,16 +193,14 @@ public final class StepDefinition {
193193 }
194194 }));
195195
196- add (Pair .with (Pattern .compile ("l\\ [\\ ]" ), s -> Collections .emptyList ()));
197- add (Pair .with (Pattern .compile ("l\\ [(.*)\\ ]" ), s -> {
198- final String [] items = s .split ("," );
199- return Stream .of (items ).map (String ::trim ).map (x -> convertToObject (x )).collect (Collectors .toList ());
196+ add (Pair .with (Pattern .compile ("^l\\ [\\ ]$" ), s -> new ArrayList <>()));
197+ add (Pair .with (Pattern .compile ("^l\\ [(.*)\\ ]$" ), s -> {
198+ return splitByElement (s ).stream ().map (x -> convertToObject (x )).collect (Collectors .toList ());
200199 }));
201200
202- add (Pair .with (Pattern .compile ("s\\ [\\ ]" ), s -> Collections .emptySet ()));
203- add (Pair .with (Pattern .compile ("s\\ [(.*)\\ ]" ), s -> {
204- final String [] items = s .split ("," );
205- return Stream .of (items ).map (String ::trim ).map (x -> convertToObject (x )).collect (Collectors .toSet ());
201+ add (Pair .with (Pattern .compile ("^s\\ [\\ ]$" ), s -> new HashSet <>()));
202+ add (Pair .with (Pattern .compile ("^s\\ [(.*)\\ ]$" ), s -> {
203+ return splitByElement (s ).stream ().map (x -> convertToObject (x )).collect (Collectors .toSet ());
206204 }));
207205
208206 // return the string values as is, used to wrap results that may contain other regex patterns
@@ -642,6 +640,27 @@ private String convertToString(final String pkey, final String pvalue) {
642640 return String .format ("\" %s\" " , pvalue );
643641 }
644642
643+ private List <String > splitByElement (String s ) {
644+ if (s .trim ().isEmpty ()) return Collections .emptyList ();
645+
646+ List <String > items = new ArrayList <>();
647+ int depth = 0 , start = 0 ;
648+
649+ for (int i = 0 ; i < s .length (); i ++) {
650+ char c = s .charAt (i );
651+ if (c == '[' || c == '{' ) depth ++;
652+ else if (c == ']' || c == '}' ) depth --;
653+ else if (c == ',' && depth == 0 ) {
654+ String item = s .substring (start , i ).trim ();
655+ if (!item .isEmpty ()) items .add (item );
656+ start = i + 1 ;
657+ }
658+ }
659+ String lastItem = s .substring (start ).trim ();
660+ if (!lastItem .isEmpty ()) items .add (lastItem );
661+ return items ;
662+ }
663+
645664 private Object convertToObject (final Object pvalue ) {
646665 final Object v ;
647666 // we may get some json stuff if it's a m[]
0 commit comments