8294626: Improve URL protocol lower casing

Reviewed-by: dfuchs
This commit is contained in:
Claes Redestad 2022-09-30 16:03:53 +00:00
parent 052a924985
commit 3efbd5f0fa
3 changed files with 22 additions and 11 deletions

View file

@ -49,8 +49,14 @@ public class URLUtil {
String protocol = url.getProtocol();
if (protocol != null) {
/* protocol is compared case-insensitive, so convert to lowercase */
protocol = protocol.toLowerCase();
/* protocol is compared case-insensitive, so convert to lowercase
* if needed. URL will store from lower-cased String literals for
* built-in protocols, so avoid calling toLowerCase for these and
* use identity tests for speed
*/
if (protocol != "file" && protocol != "jrt" && protocol != "jar") {
protocol = protocol.toLowerCase();
}
strForm.append(protocol);
strForm.append("://");
}
@ -58,8 +64,9 @@ public class URLUtil {
String host = url.getHost();
if (host != null) {
/* host is compared case-insensitive, so convert to lowercase */
host = host.toLowerCase();
strForm.append(host);
if (!host.isEmpty()) {
strForm.append(host.toLowerCase());
}
int port = url.getPort();
if (port == -1) {