Repository navigation
Fix URI type adapter to preserve identity for non-ASCII URIs - #3067
Merged
Merged
Conversation
The URI type adapter was calling `URI.toASCIIString()` in its `write()` method, which percent-encodes non-ASCII characters and applies Unicode normalization. The `read()` method does not reverse this percent-encoding, causing URIs with international characters to lose their original identity during round-trip serialization. For example, `s3://bucket/path/Kankyō.png` would fail an equality check after being serialized and deserialized. Signed-off-by: anish <anishesg@users.noreply.github.com>
Marcono1234
reviewed
Jul 22, 2026
| @@ -187,6 +187,15 @@ public void testUriDeserialization() { | |||
| assertThat(target.toASCIIString()).isEqualTo(uriValue); | |||
Contributor
There was a problem hiding this comment.
For consistency use toString() here now as well? (for that specific URI it does not make a difference though)
Suggested change
| assertThat(target.toASCIIString()).isEqualTo(uriValue); | |
| assertThat(target.toString()).isEqualTo(uriValue); |
Contributor
Author
There was a problem hiding this comment.
good catch, updated
…erialization Signed-off-by: anish <anishesg@users.noreply.github.com>
eamonnmcmanus
approved these changes
Jul 23, 2026
eamonnmcmanus
left a comment
Member
There was a problem hiding this comment.
I ran this against all of Google's internal tests and did not find any issues. That suggests that the change in behaviour is unlikely to be a problem in practice.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The URI type adapter was calling
URI.toASCIIString()in itswrite()method, which percent-encodes non-ASCII characters and applies Unicode normalization. Theread()method does not reverse this percent-encoding, causing URIs with international characters to lose their original identity during round-trip serialization. For example,s3://bucket/path/Kankyō.pngwould fail an equality check after being serialized and deserialized.The fix replaces
toASCIIString()withtoString()in line 733 of TypeAdapters.java. This preserves the original URI representation without normalization while remaining JSON-spec compliant, as JSON allows UTF-8 non-ASCII characters in strings. The change is backward compatible because pure-ASCII URIs produce identical output with both methods.A regression test was added to verify that URIs with non-ASCII characters maintain equality after round-trip serialization.
Fixes #1587