提交 bb805ffd 编写于 作者: S sherman

7005986: (zipfs) ZipPath.startsWith() fails because of the implementation of getName(index)

Summary: Updated starsWith/endsWith to be consistent with default file system
Reviewed-by: alanb
上级 226404ed
...@@ -265,7 +265,7 @@ public class ZipPath implements Path { ...@@ -265,7 +265,7 @@ public class ZipPath implements Path {
@Override @Override
public boolean isAbsolute() { public boolean isAbsolute() {
return (this.path[0] == '/'); return (this.path.length > 0 && path[0] == '/');
} }
@Override @Override
...@@ -298,32 +298,40 @@ public class ZipPath implements Path { ...@@ -298,32 +298,40 @@ public class ZipPath implements Path {
@Override @Override
public boolean startsWith(Path other) { public boolean startsWith(Path other) {
final ZipPath o = checkPath(other); final ZipPath o = checkPath(other);
if (o.isAbsolute() != this.isAbsolute()) if (o.isAbsolute() != this.isAbsolute() ||
o.path.length > this.path.length)
return false; return false;
final int oCount = o.getNameCount(); int olast = o.path.length;
if (getNameCount() < oCount) for (int i = 0; i < olast; i++) {
return false; if (o.path[i] != this.path[i])
for (int i = 0; i < oCount; i++) {
if (!o.getName(i).equals(getName(i)))
return false; return false;
} }
return true; olast--;
return o.path.length == this.path.length ||
o.path[olast] == '/' ||
this.path[olast + 1] == '/';
} }
@Override @Override
public boolean endsWith(Path other) { public boolean endsWith(Path other) {
final ZipPath o = checkPath(other); final ZipPath o = checkPath(other);
if (o.isAbsolute()) int olast = o.path.length - 1;
return this.isAbsolute() ? this.equals(o) : false; if (olast > 0 && o.path[olast] == '/')
int i = o.getNameCount(); olast--;
int j = this.getNameCount(); int last = this.path.length - 1;
if (j < i) if (last > 0 && this.path[last] == '/')
last--;
if (olast == -1) // o.path.length == 0
return last == -1;
if ((o.isAbsolute() &&(!this.isAbsolute() || olast != last)) ||
(last < olast))
return false; return false;
for (--i, --j; i >= 0; i--, j--) { for (; olast >= 0; olast--, last--) {
if (!o.getName(i).equals(this.getName(j))) if (o.path[olast] != this.path[last])
return false; return false;
} }
return true; return o.path[olast + 1] == '/' ||
last == -1 || this.path[last] == '/';
} }
@Override @Override
......
...@@ -252,31 +252,41 @@ public class PathOps { ...@@ -252,31 +252,41 @@ public class PathOps {
.name("foo"); .name("foo");
// startsWith // startsWith
test("")
.starts("")
.notStarts("/");
test("/") test("/")
.starts("/") .starts("/")
.notStarts("/foo"); .notStarts("/foo");
test("/foo") test("/foo")
.starts("/") .starts("/")
.starts("/foo") .starts("/foo")
.notStarts("/f"); .notStarts("/f")
.notStarts("");
test("/foo/bar") test("/foo/bar")
.starts("/") .starts("/")
.starts("/foo") .starts("/foo")
.starts("/foo/")
.starts("/foo/bar") .starts("/foo/bar")
.notStarts("/f") .notStarts("/f")
.notStarts("foo") .notStarts("foo")
.notStarts("foo/bar"); .notStarts("foo/bar")
.notStarts("");
test("foo") test("foo")
.starts("foo") .starts("foo")
.notStarts("f"); .notStarts("f");
test("foo/bar") test("foo/bar")
.starts("foo") .starts("foo")
.starts("foo/")
.starts("foo/bar") .starts("foo/bar")
.notStarts("f") .notStarts("f")
.notStarts("/foo") .notStarts("/foo")
.notStarts("/foo/bar"); .notStarts("/foo/bar");
// endsWith // endsWith
test("")
.ends("")
.notEnds("/");
test("/") test("/")
.ends("/") .ends("/")
.notEnds("foo") .notEnds("foo")
...@@ -288,14 +298,24 @@ public class PathOps { ...@@ -288,14 +298,24 @@ public class PathOps {
test("/foo/bar") test("/foo/bar")
.ends("bar") .ends("bar")
.ends("foo/bar") .ends("foo/bar")
.ends("foo/bar/")
.ends("/foo/bar")
.notEnds("/bar");
test("/foo/bar/")
.ends("bar")
.ends("foo/bar")
.ends("foo/bar/")
.ends("/foo/bar") .ends("/foo/bar")
.notEnds("/bar"); .notEnds("/bar");
test("foo") test("foo")
.ends("foo"); .ends("foo");
test("foo/bar") test("foo/bar")
.ends("bar") .ends("bar")
.ends("bar/")
.ends("foo/bar/")
.ends("foo/bar"); .ends("foo/bar");
// elements // elements
test("a/b/c") test("a/b/c")
.element(0,"a") .element(0,"a")
...@@ -309,6 +329,8 @@ public class PathOps { ...@@ -309,6 +329,8 @@ public class PathOps {
.absolute(); .absolute();
test("tmp") test("tmp")
.notAbsolute(); .notAbsolute();
test("")
.notAbsolute();
// resolve // resolve
test("/tmp") test("/tmp")
......
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
# questions. # questions.
# #
# @test # @test
# @bug 6990846 7009092 7009085 7015391 7014948 # @bug 6990846 7009092 7009085 7015391 7014948 7005986
# @summary Test ZipFileSystem demo # @summary Test ZipFileSystem demo
# @build Basic PathOps ZipFSTester # @build Basic PathOps ZipFSTester
# @run shell basic.sh # @run shell basic.sh
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册