mirror of
https://github.com/openjdk/jdk.git
synced 2026-06-02 00:34:44 +00:00
7005986: (zipfs) ZipPath.startsWith() fails because of the implementation of getName(index)
Updated starsWith/endsWith to be consistent with default file system Reviewed-by: alanb
This commit is contained in:
parent
50cd98ab88
commit
4f8fd33ba8
@ -265,7 +265,7 @@ public class ZipPath implements Path {
|
||||
|
||||
@Override
|
||||
public boolean isAbsolute() {
|
||||
return (this.path[0] == '/');
|
||||
return (this.path.length > 0 && path[0] == '/');
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -298,32 +298,40 @@ public class ZipPath implements Path {
|
||||
@Override
|
||||
public boolean startsWith(Path other) {
|
||||
final ZipPath o = checkPath(other);
|
||||
if (o.isAbsolute() != this.isAbsolute())
|
||||
if (o.isAbsolute() != this.isAbsolute() ||
|
||||
o.path.length > this.path.length)
|
||||
return false;
|
||||
final int oCount = o.getNameCount();
|
||||
if (getNameCount() < oCount)
|
||||
return false;
|
||||
for (int i = 0; i < oCount; i++) {
|
||||
if (!o.getName(i).equals(getName(i)))
|
||||
int olast = o.path.length;
|
||||
for (int i = 0; i < olast; i++) {
|
||||
if (o.path[i] != this.path[i])
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
olast--;
|
||||
return o.path.length == this.path.length ||
|
||||
o.path[olast] == '/' ||
|
||||
this.path[olast + 1] == '/';
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean endsWith(Path other) {
|
||||
final ZipPath o = checkPath(other);
|
||||
if (o.isAbsolute())
|
||||
return this.isAbsolute() ? this.equals(o) : false;
|
||||
int i = o.getNameCount();
|
||||
int j = this.getNameCount();
|
||||
if (j < i)
|
||||
int olast = o.path.length - 1;
|
||||
if (olast > 0 && o.path[olast] == '/')
|
||||
olast--;
|
||||
int last = this.path.length - 1;
|
||||
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;
|
||||
for (--i, --j; i >= 0; i--, j--) {
|
||||
if (!o.getName(i).equals(this.getName(j)))
|
||||
for (; olast >= 0; olast--, last--) {
|
||||
if (o.path[olast] != this.path[last])
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
return o.path[olast + 1] == '/' ||
|
||||
last == -1 || this.path[last] == '/';
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -252,31 +252,41 @@ public class PathOps {
|
||||
.name("foo");
|
||||
|
||||
// startsWith
|
||||
test("")
|
||||
.starts("")
|
||||
.notStarts("/");
|
||||
test("/")
|
||||
.starts("/")
|
||||
.notStarts("/foo");
|
||||
test("/foo")
|
||||
.starts("/")
|
||||
.starts("/foo")
|
||||
.notStarts("/f");
|
||||
.notStarts("/f")
|
||||
.notStarts("");
|
||||
test("/foo/bar")
|
||||
.starts("/")
|
||||
.starts("/foo")
|
||||
.starts("/foo/")
|
||||
.starts("/foo/bar")
|
||||
.notStarts("/f")
|
||||
.notStarts("foo")
|
||||
.notStarts("foo/bar");
|
||||
.notStarts("foo/bar")
|
||||
.notStarts("");
|
||||
test("foo")
|
||||
.starts("foo")
|
||||
.notStarts("f");
|
||||
test("foo/bar")
|
||||
.starts("foo")
|
||||
.starts("foo/")
|
||||
.starts("foo/bar")
|
||||
.notStarts("f")
|
||||
.notStarts("/foo")
|
||||
.notStarts("/foo/bar");
|
||||
|
||||
// endsWith
|
||||
test("")
|
||||
.ends("")
|
||||
.notEnds("/");
|
||||
test("/")
|
||||
.ends("/")
|
||||
.notEnds("foo")
|
||||
@ -288,14 +298,24 @@ public class PathOps {
|
||||
test("/foo/bar")
|
||||
.ends("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")
|
||||
.notEnds("/bar");
|
||||
test("foo")
|
||||
.ends("foo");
|
||||
test("foo/bar")
|
||||
.ends("bar")
|
||||
.ends("bar/")
|
||||
.ends("foo/bar/")
|
||||
.ends("foo/bar");
|
||||
|
||||
|
||||
// elements
|
||||
test("a/b/c")
|
||||
.element(0,"a")
|
||||
@ -309,6 +329,8 @@ public class PathOps {
|
||||
.absolute();
|
||||
test("tmp")
|
||||
.notAbsolute();
|
||||
test("")
|
||||
.notAbsolute();
|
||||
|
||||
// resolve
|
||||
test("/tmp")
|
||||
|
||||
@ -21,7 +21,7 @@
|
||||
# questions.
|
||||
#
|
||||
# @test
|
||||
# @bug 6990846 7009092 7009085 7015391 7014948
|
||||
# @bug 6990846 7009092 7009085 7015391 7014948 7005986
|
||||
# @summary Test ZipFileSystem demo
|
||||
# @build Basic PathOps ZipFSTester
|
||||
# @run shell basic.sh
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user