Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f240cb80 authored by Adam Vartanian's avatar Adam Vartanian
Browse files

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
parent 762f9f0c
Loading
Loading
Loading
Loading
+1 −2
Original line number Diff line number Diff line
@@ -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());