File tree Expand file tree Collapse file tree 1 file changed +22
-3
lines changed
Expand file tree Collapse file tree 1 file changed +22
-3
lines changed Original file line number Diff line number Diff line change @@ -158,9 +158,28 @@ public JSONPointer(final String pointer) {
158158 throw new IllegalArgumentException ("a JSON pointer should start with '/' or '#/'" );
159159 }
160160 this .refTokens = new ArrayList <String >();
161- for (String token : refs .split ("/" )) {
162- this .refTokens .add (unescape (token ));
163- }
161+ int slashIdx = -1 ;
162+ int prevSlashIdx = 0 ;
163+ do {
164+ prevSlashIdx = slashIdx + 1 ;
165+ slashIdx = refs .indexOf ('/' , prevSlashIdx );
166+ if (prevSlashIdx == slashIdx || prevSlashIdx == refs .length ()) {
167+ // found 2 slashes in a row ( obj//next )
168+ // or single slash at the end of a string ( obj/test/ )
169+ this .refTokens .add ("" );
170+ } else if (slashIdx >= 0 ) {
171+ final String token = refs .substring (prevSlashIdx , slashIdx );
172+ this .refTokens .add (unescape (token ));
173+ } else {
174+ // last item after separator, or no separator at all.
175+ final String token = refs .substring (prevSlashIdx );
176+ this .refTokens .add (unescape (token ));
177+ }
178+ } while (slashIdx >= 0 );
179+ // using split does not take into account consecutive separators or "ending nulls"
180+ //for (String token : refs.split("/")) {
181+ // this.refTokens.add(unescape(token));
182+ //}
164183 }
165184
166185 public JSONPointer (List <String > refTokens ) {
You can’t perform that action at this time.
0 commit comments