From ff2c987669523613f3e5dc19493a41f849f882f6 Mon Sep 17 00:00:00 2001 From: Ryan Wallace Date: Sat, 12 Nov 2022 01:37:46 +0000 Subject: [PATCH] 8294378: URLPermission constructor exception when using tr locale Reviewed-by: dfuchs, jpai, aefimov --- .../share/classes/java/net/HostPortrange.java | 3 +++ .../share/classes/java/net/URLPermission.java | 5 +++-- test/jdk/java/net/URLPermission/URLPermissionTest.java | 10 +++++++--- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/java.base/share/classes/java/net/HostPortrange.java b/src/java.base/share/classes/java/net/HostPortrange.java index 5e0696309d0..687bb3737d1 100644 --- a/src/java.base/share/classes/java/net/HostPortrange.java +++ b/src/java.base/share/classes/java/net/HostPortrange.java @@ -149,6 +149,9 @@ class HostPortrange { // regular domain name hoststr = toLowerCase(hoststr); } + } else { + // regular domain name + hoststr = toLowerCase(hoststr); } } hostname = hoststr; diff --git a/src/java.base/share/classes/java/net/URLPermission.java b/src/java.base/share/classes/java/net/URLPermission.java index 1ad0513768e..4ee5cddaff8 100644 --- a/src/java.base/share/classes/java/net/URLPermission.java +++ b/src/java.base/share/classes/java/net/URLPermission.java @@ -31,6 +31,7 @@ import java.util.List; import java.util.ArrayList; import java.util.Collections; import java.security.Permission; +import java.util.Locale; /** * Represents permission to access a resource or set of resources defined by a @@ -471,7 +472,7 @@ public final class URLPermission extends Permission { throw new IllegalArgumentException( "Invalid URL string: \"" + url + "\""); } - scheme = url.substring(0, delim).toLowerCase(); + scheme = url.substring(0, delim).toLowerCase(Locale.ROOT); this.ssp = url.substring(delim + 1); if (!ssp.startsWith("//")) { @@ -493,7 +494,7 @@ public final class URLPermission extends Permission { auth = authpath.substring(0, delim); this.path = authpath.substring(delim); } - this.authority = new Authority(scheme, auth.toLowerCase()); + this.authority = new Authority(scheme, auth); } private String actions() { diff --git a/test/jdk/java/net/URLPermission/URLPermissionTest.java b/test/jdk/java/net/URLPermission/URLPermissionTest.java index b170850c702..d31001fd584 100644 --- a/test/jdk/java/net/URLPermission/URLPermissionTest.java +++ b/test/jdk/java/net/URLPermission/URLPermissionTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2013, 2022, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -26,7 +26,9 @@ import java.io.*; /** * @test - * @bug 8010464 8027570 8027687 8029354 8114860 8071660 8161291 + * @bug 8010464 8027570 8027687 8029354 8114860 8071660 8161291 8294378 + * @run main URLPermissionTest + * @run main/othervm -Duser.language=tr URLPermissionTest */ public class URLPermissionTest { @@ -392,7 +394,9 @@ public class URLPermissionTest { eqtest("http://michael@foo.com/bar","http://michael@foo.com/bar", true), eqtest("http://Michael@foo.com/bar","http://michael@goo.com/bar",false), eqtest("http://michael@foo.com/bar","http://george@foo.com/bar", true), - eqtest("http://@foo.com/bar","http://foo.com/bar", true) + eqtest("http://@foo.com/bar","http://foo.com/bar", true), + eqtest("http://www.IOU.com", "http://www.iou.com", true), + eqtest("HTTPI://www.IOU.com", "httpi://www.iou.com", true) }; static Test[] createTests = {