Skip to content

Commit bcee700

Browse files
committed
8273961: jdk/nio/zipfs/ZipFSTester.java fails if file path contains '+' character
Reviewed-by: mdoerr Backport-of: 7f78803b0926ea194334ad9b3c9f06cbe17a83dd
1 parent 4e63adb commit bcee700

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, 2018, 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
@@ -689,10 +689,19 @@ private static FileSystem newZipFileSystem(Path path, Map<String, ?> env)
689689
throws Exception
690690
{
691691
// Use URLDecoder (for test only) to remove the double escaped space
692-
// character
692+
// character. For the path which is not encoded by UTF-8, we need to
693+
// replace "+" by "%2b" manually before feeding into the decoder.
694+
// Otherwise, the URLDecoder would replace "+" by " ", which may
695+
// raise NoSuchFileException.
696+
//
697+
// eg. var path = "file:///jdk-18+9/basic.jar";
698+
// URLDecoder.decode(path, "utf8") -> file:///jdk-18 9/basic.jar
699+
//
700+
// Also, we should not use URLEncoder in case of the path has been
701+
// encoded.
693702
return FileSystems.newFileSystem(
694-
new URI("jar", URLDecoder.decode(path.toUri().toString(), "utf8"),
695-
null), env, null);
703+
new URI("jar", URLDecoder.decode(path.toUri().toString()
704+
.replace("+", "%2b"), "utf8"), null), env, null);
696705
}
697706

698707
private static Path getTempPath() throws IOException

0 commit comments

Comments
 (0)