Skip to content

Commit 4b9d186

Browse files
committed
api: Warn callers to choose carefully between raw and cooked fragment
1 parent 0248e6f commit 4b9d186

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -573,6 +573,19 @@ public String getRawQuery() {
573573
* <p>Decoding errors are indicated by a {@code '\u005CuFFFD'} unicode replacement character in
574574
* the output. Callers who want to detect and handle errors in some other way should call {@link
575575
* #getRawFragment()}, {@link #percentDecode(CharSequence)}, then decode the bytes for themselves.
576+
*
577+
* <p>NB: Choose carefully between this method and {@link #getRawFragment()}. Many URI schemes
578+
* embed further structure inside the fragment that isn't part of the RFC 3986 generic syntax. For
579+
* example, Android uses the fragment to encode the many fields of an Intent, like {@code
580+
* intent:#Intent;S.key=val;end;}. And the URI of a JSON resource may use RFC 6901 in its fragment
581+
* to point at a particular node, e.g. {@code
582+
* file:/etc/config/service.json#/methodConfig/0/retryPolicy/maxBackoff}.
583+
*
584+
* <p>When percent-encoding is used to escape internal delimiters, like a literal ';' and '=' in
585+
* an `intent:`, call {@link #getRawFragment()} to preserve that percent-encoding, or risk
586+
* corruption. Conversely, use *this* method when percent-decoding is needed *before* any further
587+
* interpretation, like with a JSON pointer, which must be percent-encoded in a URI fragment but
588+
* uses a completely different method of escaping literal '/' characters.
576589
*/
577590
@Nullable
578591
public String getFragment() {
@@ -582,6 +595,9 @@ public String getFragment() {
582595
/**
583596
* Returns the fragment component of this URI in its original, possibly percent-encoded form, and
584597
* without any leading '#' character.
598+
*
599+
* <p>NB: Choose carefully between this method and {@link #getFragment()}. See that Javadoc for
600+
* details.
585601
*/
586602
@Nullable
587603
public String getRawFragment() {

0 commit comments

Comments
 (0)