Skip to content

Commit 78566ff

Browse files
committed
api: Add a warning about Uri#getAuthority just like getPath()
1 parent 650dee1 commit 78566ff

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

api/src/main/java/io/grpc/Uri.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,15 @@ public String getScheme() {
356356
/**
357357
* Returns the percent-decoded "Authority" component of this URI, or null if not present.
358358
*
359+
* <p>NB: This method's decoding is lossy -- It only exists for compatibility with {@link
360+
* java.net.URI}. Prefer {@link #getRawAuthority()} or work instead with authority in terms of its
361+
* individual components ({@link #getUserInfo()}, {@link #getHost()} and {@link #getPort()}). The
362+
* problem with getAuthority() is that it returns the delimited concatenation of the percent-
363+
* decoded userinfo, host and port components. But both userinfo and host can contain the '@'
364+
* character, which becomes indistinguishable from the userinfo/host delimiter after decoding. For
365+
* example, URIs <code>scheme://x@y%40z</code> and <code>scheme://x%40y@z</code> have different
366+
* userinfo and host components but getAuthority() returns "x@y@z" for both of them.
367+
*
359368
* <p>NB: This method assumes the "host" component was encoded as UTF-8, as mandated by RFC 3986.
360369
* This method also assumes the "user information" part of authority was encoded as UTF-8,
361370
* although RFC 3986 doesn't specify an encoding.

0 commit comments

Comments
 (0)