From f240cb809173afe453c5d8982477ef22166dbc60 Mon Sep 17 00:00:00 2001 From: Adam Vartanian Date: Mon, 18 Feb 2019 12:01:11 +0000 Subject: [PATCH] Fix authority parsing test The test has been failing because http://r.android.com/793302 changed how the port separator was found, only scanning ASCII digits until it hits a colon, and previously it would scan for the colon and then percent-decode the rest of it. The new behavior actually better matches the WHATWG URL parsing algorithm [1], which specifies that ports only include ASCII digits. It does mean that some edge cases that previously parsed as host "foo", port 42 will now parse as host "foo:42", no port, but those URLs wouldn't be accepted by browsers so they should be exceedingly rare. The behavior per the WHATWG spec would be to fail to parse in the case of a percent-encoded character in the port section, but this class is specifically documented to accept garbage, so lumping the mis-encoded port as part of the hostname (which will result in a hostname that's invalid and impossible to resolve) seems like the best option. [1] https://url.spec.whatwg.org/#port-state Fixes: 124360078 Test: atest android.net.UriTest Change-Id: I1c788cb7703c821ae74b542b74d89e10cba5a546 --- core/tests/coretests/src/android/net/UriTest.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/core/tests/coretests/src/android/net/UriTest.java b/core/tests/coretests/src/android/net/UriTest.java index ea0347d67ad74..f1d5600b96509 100644 --- a/core/tests/coretests/src/android/net/UriTest.java +++ b/core/tests/coretests/src/android/net/UriTest.java @@ -181,8 +181,7 @@ public class UriTest extends TestCase { uri = Uri.parse("http://bob%40lee%3ajr@local%68ost:4%32"); assertEquals("bob@lee:jr", uri.getUserInfo()); - assertEquals("localhost", uri.getHost()); - assertEquals(42, uri.getPort()); + assertEquals("localhost:42", uri.getHost()); uri = Uri.parse("http://localhost"); assertEquals("localhost", uri.getHost());