diff --git a/core/java/android/net/WebAddress.java b/core/java/android/net/WebAddress.java index 4101ab489308d..9c4d6e882b595 100644 --- a/core/java/android/net/WebAddress.java +++ b/core/java/android/net/WebAddress.java @@ -56,7 +56,7 @@ public class WebAddress { static Pattern sAddressPattern = Pattern.compile( /* scheme */ "(?:(http|https|file)\\:\\/\\/)?" + /* authority */ "(?:([-A-Za-z0-9$_.+!*'(),;?&=]+(?:\\:[-A-Za-z0-9$_.+!*'(),;?&=]+)?)@)?" + - /* host */ "([-" + GOOD_IRI_CHAR + "%_]+(?:\\.[-" + GOOD_IRI_CHAR + "%_]+)*|\\[[0-9a-fA-F:\\.]+\\])?" + + /* host */ "([" + GOOD_IRI_CHAR + "%_-][" + GOOD_IRI_CHAR + "%_\\.-]*|\\[[0-9a-fA-F:\\.]+\\])?" + /* port */ "(?:\\:([0-9]*))?" + /* path */ "(\\/?[^#]*)?" + /* anchor */ ".*", Pattern.CASE_INSENSITIVE); diff --git a/core/tests/coretests/src/android/net/UriTest.java b/core/tests/coretests/src/android/net/UriTest.java index fe608b5f31e4b..60c3c76c01aab 100644 --- a/core/tests/coretests/src/android/net/UriTest.java +++ b/core/tests/coretests/src/android/net/UriTest.java @@ -285,6 +285,13 @@ public class UriTest extends TestCase { assertEquals("d", uri.getQueryParameter("c")); } + @SmallTest + public void testHostWithTrailingDot() { + Uri uri = Uri.parse("http://google.com./b/c/g"); + assertEquals("google.com.", uri.getHost()); + assertEquals("/b/c/g", uri.getPath()); + } + @SmallTest public void testSchemeOnly() { Uri uri = Uri.parse("empty:"); diff --git a/core/tests/coretests/src/android/net/WebAddressTest.java b/core/tests/coretests/src/android/net/WebAddressTest.java new file mode 100644 index 0000000000000..7ca1e6246618b --- /dev/null +++ b/core/tests/coretests/src/android/net/WebAddressTest.java @@ -0,0 +1,31 @@ +/* + * 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 android.net; + +import android.net.WebAddress; +import android.test.suitebuilder.annotation.SmallTest; +import junit.framework.TestCase; + +public class WebAddressTest extends TestCase { + + @SmallTest + public void testHostWithTrailingDot() { + WebAddress webAddress = new WebAddress("http://google.com./b/c/g"); + assertEquals("google.com.", webAddress.mHost); + assertEquals("/b/c/g", webAddress.mPath); + } +}