changeset 35381:2545709d9a45

8147962: URL should handle lower-casing of protocol locale-independently Reviewed-by: chegar, alanb, naoto
author redestad
date Wed, 27 Jan 2016 13:51:35 +0100
parents 0a1bb3578de4
children 1f36500e84c7
files jdk/src/java.base/share/classes/java/net/URL.java jdk/test/java/net/URL/LocaleDependentURLTest.java
diffstat 2 files changed, 44 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/jdk/src/java.base/share/classes/java/net/URL.java	Tue Jan 26 15:30:42 2016 -0800
+++ b/jdk/src/java.base/share/classes/java/net/URL.java	Wed Jan 27 13:51:35 2016 +0100
@@ -36,6 +36,7 @@
 import java.io.ObjectStreamField;
 import java.io.ObjectInputStream.GetField;
 import java.util.Iterator;
+import java.util.Locale;
 import java.util.NoSuchElementException;
 import java.util.ServiceConfigurationError;
 import java.util.ServiceLoader;
@@ -405,7 +406,7 @@
             }
         }
 
-        protocol = protocol.toLowerCase();
+        protocol = protocol.toLowerCase(Locale.ROOT);
         this.protocol = protocol;
         if (host != null) {
 
@@ -579,8 +580,7 @@
             for (i = start ; !aRef && (i < limit) &&
                      ((c = spec.charAt(i)) != '/') ; i++) {
                 if (c == ':') {
-
-                    String s = spec.substring(start, i).toLowerCase();
+                    String s = spec.substring(start, i).toLowerCase(Locale.ROOT);
                     if (isValidProtocol(s)) {
                         newProtocol = s;
                         start = i + 1;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/net/URL/LocaleDependentURLTest.java	Wed Jan 27 13:51:35 2016 +0100
@@ -0,0 +1,41 @@
+/*
+ * Copyright (c) 2016, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/* @test
+ * @bug 8147962
+ * @summary Verify URLs with upper-case protocols parse correctly in any
+ *          locale
+ * @run main/othervm LocaleDependentURLTest
+ */
+import java.net.*;
+import java.util.Locale;
+
+public class LocaleDependentURLTest {
+
+    public static void main(String args[]) throws MalformedURLException {
+        for (Locale locale : Locale.getAvailableLocales()) {
+            Locale.setDefault(locale);
+            new URL("FILE:///TMP/X");
+        }
+    }
+}