Skip to content

Commit

Permalink
Fixed getParent which led to infinite loops under rare circumstances
Browse files Browse the repository at this point in the history
  • Loading branch information
markuskreusch committed Apr 25, 2017
1 parent 831cc0a commit 62b73c0
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/main/java/org/cryptomator/cryptofs/CryptoPath.java
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,10 @@ public CryptoPath getParent() {
if (elementCount > 1) {
List<String> elems = elements.subList(0, elementCount - 1);
return copyWithElements(elems);
} else {
} else if (elementCount == 1) {
return getRoot();
} else {
return null;
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/test/java/org/cryptomator/cryptofs/CryptoPathTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,13 @@ public void testGetParent() {
Path p1 = path("/foo");
Path p2 = path("/foo/bar");
Path p3 = path("foo");
Path p4 = path("/");

Assert.assertEquals(p1, p2.getParent());
Assert.assertEquals(rootPath, p1.getParent());
Assert.assertNull(emptyPath.getParent());
Assert.assertNull(p3.getParent());
Assert.assertNull(p4.getParent());
}

@Test
Expand Down

0 comments on commit 62b73c0

Please sign in to comment.