Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.regex.Pattern;

public class ObjectIdentifier {

Expand Down Expand Up @@ -51,7 +52,8 @@ public static ObjectIdentifier of(String id, String delimiter) {
if (id.equals(delimiter)) {
return new ObjectIdentifier(new String[0]);
}
return new ObjectIdentifier(id.split(delimiter));
// Split by the delimiter literally(i.e., escape any regex special characters)
return new ObjectIdentifier(id.split(Pattern.quote(delimiter)));
}

public String levelAtListPos(int pos) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,5 +67,15 @@ public void testObjectIdentifier() {

oid = ObjectIdentifier.of(Lists.newArrayList("a", "b", "c"));
assertEquals(Lists.newArrayList("a", "b"), oid.parent());

// Case 5: parse from string
oid = ObjectIdentifier.of(".");
assertEquals(0, oid.levels());

oid = ObjectIdentifier.of("a.b.c");
assertEquals(3, oid.levels());
assertEquals("a", oid.levelAtListPos(0));
assertEquals("b", oid.levelAtListPos(1));
assertEquals("c", oid.levelAtListPos(2));
}
}