Ban call of URLEncoder.encode/URLDecoder.decode(String,String)

Add ArchUnit rules to ban the use of `URLEncoder` calls with String
charsets and use `Charset` calls instead.

See gh-38740
This commit is contained in:
Yanming Zhou
2023-12-12 12:01:01 +08:00
committed by Phillip Webb
parent ae79a7c00f
commit 8cb8999772
6 changed files with 33 additions and 17 deletions

View File

@@ -23,6 +23,7 @@ import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLClassLoader;
import java.net.URLDecoder;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
@@ -159,7 +160,7 @@ final class ChangeableUrls implements Iterable<URL> {
urls.add(referenced);
}
else {
referenced = new URL(jarUrl, URLDecoder.decode(entry, "UTF-8"));
referenced = new URL(jarUrl, URLDecoder.decode(entry, StandardCharsets.UTF_8));
if (new File(referenced.getFile()).exists()) {
urls.add(referenced);
}