Skip to content
Commit c9afa38f authored by Tobias Thierer's avatar Tobias Thierer
Browse files

Parcel only the canonical Uri.Part representation, not both.

Before this CL, Uri.AbstractPart's implementation of Parcelable
was parceling and unparceling both the encoded and the decoded
representation. A Uri with inconsistent decoded/encoded
representation of its Parts would have remained inconsistent
across parcel/unparcel cycles. For example, such a Uri's
uri.getDecodedAuthority() might have returned "good.com" while
url.getEncodedAuthority() (used e.g. for toString()) returned
"evil.com".

After this CL, AbstractPart's constructor allows at most one of
the representations to be set (exception: NULL and EMPTY); this
means that no Part instance with inconsistent values can be
constructed via the constructor (e.g. by unparceling parceled
data). The historical parcel representation of a Part with both
values present can no longer be unparceled, which is safe because
Parcel does not guarantee backwards compatibility (the parceled
form must not be persisted across Android version upgrades).

When parceling, only one of the values is now stored, namely
the (canonical) one that was passed to the constructor.

Bug: 124526860
Test: atest FrameworksCoreTests:android.net.UriTest
Test: Checked that if run before this CL, the added tests
      would fail with a failure along the lines of:
      ComparisonFailure: expected:</foo/[b]> but was:</foo/[a]>
      or (if the first assertion was commented out):
      ComparisonFailure: expected:<[b].com> but was:<[a].com>

Change-Id: I2bc2008e49de5a66641ecdbd8e5354dfa647269d
parent b639ce9e
Loading
Loading
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment