diff options
-rw-r--r-- | luni/src/main/java/java/net/URI.java | 14 | ||||
-rw-r--r-- | luni/src/test/java/java/net/AllTests.java | 7 | ||||
-rw-r--r-- | luni/src/test/java/java/net/UriTest.java | 29 |
3 files changed, 42 insertions, 8 deletions
diff --git a/luni/src/main/java/java/net/URI.java b/luni/src/main/java/java/net/URI.java index 85c16eb..36637c6 100644 --- a/luni/src/main/java/java/net/URI.java +++ b/luni/src/main/java/java/net/URI.java @@ -619,17 +619,21 @@ public final class URI implements Comparable<URI>, Serializable { return false; } - String label = null; + String lastLabel = null; StringTokenizer st = new StringTokenizer(host, "."); //$NON-NLS-1$ while (st.hasMoreTokens()) { - label = st.nextToken(); - if (label.startsWith("-") || label.endsWith("-")) { //$NON-NLS-1$ //$NON-NLS-2$ + lastLabel = st.nextToken(); + if (lastLabel.startsWith("-") || lastLabel.endsWith("-")) { //$NON-NLS-1$ //$NON-NLS-2$ return false; } } - if (!label.equals(host)) { - char ch = label.charAt(0); + if (lastLabel == null) { + return false; + } + + if (!lastLabel.equals(host)) { + char ch = lastLabel.charAt(0); if (ch >= '0' && ch <= '9') { return false; } diff --git a/luni/src/test/java/java/net/AllTests.java b/luni/src/test/java/java/net/AllTests.java index dbfb3e4..226e2c3 100644 --- a/luni/src/test/java/java/net/AllTests.java +++ b/luni/src/test/java/java/net/AllTests.java @@ -22,9 +22,10 @@ import junit.framework.TestSuite; public class AllTests { public static final Test suite() { TestSuite suite = new TestSuite(); - suite.addTestSuite(java.net.IDNTest.class); - suite.addTestSuite(java.net.SocketTest.class); - suite.addTestSuite(java.net.URLConnectionTest.class); + suite.addTestSuite(IDNTest.class); + suite.addTestSuite(SocketTest.class); + suite.addTestSuite(URLConnectionTest.class); + suite.addTestSuite(UriTest.class); return suite; } } diff --git a/luni/src/test/java/java/net/UriTest.java b/luni/src/test/java/java/net/UriTest.java new file mode 100644 index 0000000..9900d5e --- /dev/null +++ b/luni/src/test/java/java/net/UriTest.java @@ -0,0 +1,29 @@ +/* + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package java.net; + +import junit.framework.TestCase; + +public class UriTest extends TestCase { + + /** + * Regression test for http://b/issue?id=2604061 + */ + public void testParsingDotAsHostname() throws URISyntaxException { + assertEquals(null, new URI("http://./").getHost()); + } +} |