Skip to content

Commit 7f78803

Browse files
1996scarletLance Andersen
authored andcommitted
8273961: jdk/nio/zipfs/ZipFSTester.java fails if file path contains '+' character
Reviewed-by: clanger, lancea
1 parent 51085b5 commit 7f78803

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

test/jdk/jdk/nio/zipfs/ZipFSTester.java

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2010, 2019, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2010, 2021, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -73,7 +73,7 @@
7373
* @test
7474
* @bug 6990846 7009092 7009085 7015391 7014948 7005986 7017840 7007596
7575
* 7157656 8002390 7012868 7012856 8015728 8038500 8040059 8069211
76-
* 8131067 8034802 8210899
76+
* 8131067 8034802 8210899 8273961
7777
* @summary Test Zip filesystem provider
7878
* @modules jdk.zipfs
7979
* @run main ZipFSTester
@@ -687,10 +687,19 @@ private static FileSystem newZipFileSystem(Path path, Map<String, ?> env)
687687
throws Exception
688688
{
689689
// Use URLDecoder (for test only) to remove the double escaped space
690-
// character
690+
// character. For the path which is not encoded by UTF-8, we need to
691+
// replace "+" by "%2b" manually before feeding into the decoder.
692+
// Otherwise, the URLDecoder would replace "+" by " ", which may
693+
// raise NoSuchFileException.
694+
//
695+
// eg. var path = "file:///jdk-18+9/basic.jar";
696+
// URLDecoder.decode(path, "utf8") -> file:///jdk-18 9/basic.jar
697+
//
698+
// Also, we should not use URLEncoder in case of the path has been
699+
// encoded.
691700
return FileSystems.newFileSystem(
692-
new URI("jar", URLDecoder.decode(path.toUri().toString(), "utf8"),
693-
null), env, null);
701+
new URI("jar", URLDecoder.decode(path.toUri().toString()
702+
.replace("+", "%2b"), "utf8"), null), env, null);
694703
}
695704

696705
private static Path getTempPath() throws IOException

0 commit comments

Comments
 (0)