• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

grpc / grpc-java / #20222

26 Mar 2026 12:08AM UTC coverage: 88.715% (+0.03%) from 88.69%
#20222

push

github

jdcormie
googleapis: Add RFC 3986 URI support.

35501 of 40017 relevant lines covered (88.71%)

0.89 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

98.07
/../api/src/main/java/io/grpc/Uri.java
1
/*
2
 * Copyright 2025 The gRPC Authors
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at
7
 *
8
 *     http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * See the License for the specific language governing permissions and
14
 * limitations under the License.
15
 */
16

17
package io.grpc;
18

19
import static com.google.common.base.Preconditions.checkArgument;
20
import static com.google.common.base.Preconditions.checkNotNull;
21
import static com.google.common.base.Preconditions.checkState;
22

23
import com.google.common.base.VerifyException;
24
import com.google.common.collect.ImmutableList;
25
import com.google.common.net.InetAddresses;
26
import com.google.errorprone.annotations.CanIgnoreReturnValue;
27
import java.net.InetAddress;
28
import java.net.URISyntaxException;
29
import java.nio.ByteBuffer;
30
import java.nio.CharBuffer;
31
import java.nio.charset.CharacterCodingException;
32
import java.nio.charset.CharsetEncoder;
33
import java.nio.charset.CodingErrorAction;
34
import java.nio.charset.MalformedInputException;
35
import java.nio.charset.StandardCharsets;
36
import java.util.BitSet;
37
import java.util.List;
38
import java.util.Locale;
39
import java.util.Objects;
40
import javax.annotation.Nullable;
41

42
/**
43
 * A not-quite-general-purpose representation of a Uniform Resource Identifier (URI), as defined by
44
 * <a href="https://datatracker.ietf.org/doc/html/rfc3986">RFC 3986</a>.
45
 *
46
 * <h1>The URI</h1>
47
 *
48
 * <p>A URI identifies a resource by its name or location or both. The resource could be a file,
49
 * service, or some other abstract entity.
50
 *
51
 * <h2>Examples</h2>
52
 *
53
 * <ul>
54
 *   <li><code>http://admin@example.com:8080/controlpanel?filter=users#settings</code>
55
 *   <li><code>ftp://[2001:db8::7]/docs/report.pdf</code>
56
 *   <li><code>file:///My%20Computer/Documents/letter.doc</code>
57
 *   <li><code>dns://8.8.8.8/storage.googleapis.com</code>
58
 *   <li><code>mailto:John.Doe@example.com</code>
59
 *   <li><code>tel:+1-206-555-1212</code>
60
 *   <li><code>urn:isbn:978-1492082798</code>
61
 * </ul>
62
 *
63
 * <h2>Limitations</h2>
64
 *
65
 * <p>This class aims to meet the needs of grpc-java itself and RPC related code that depend on it.
66
 * It isn't quite general-purpose. It definitely would not be suitable for building an HTTP user
67
 * agent or proxy server. In particular, it:
68
 *
69
 * <ul>
70
 *   <li>Can only represent a URI, not a "URI-reference" or "relative reference". In other words, a
71
 *       "scheme" is always required.
72
 *   <li>Has no knowledge of the particulars of any scheme, with respect to normalization and
73
 *       comparison. We don't know <code>https://google.com</code> is the same as <code>
74
 *       https://google.com:443</code>, that <code>file:///</code> is the same as <code>
75
 *       file://localhost</code>, or that <code>joe@example.com</code> is the same as <code>
76
 *       joe@EXAMPLE.COM</code>. No one class can or should know everything about every scheme so
77
 *       all this is better handled at a higher layer.
78
 *   <li>Implements {@link #equals(Object)} as a char-by-char comparison. Expect false negatives.
79
 *   <li>Does not support "IPvFuture" literal addresses.
80
 *   <li>Does not reflect how web browsers parse user input or the <a
81
 *       href="https://url.spec.whatwg.org/">URL Living Standard</a>.
82
 *   <li>Does not support different character encodings. Assumes UTF-8 in several places.
83
 * </ul>
84
 *
85
 * <h2>Migrating from RFC 2396 and {@link java.net.URI}</h2>
86
 *
87
 * <p>Those migrating from {@link java.net.URI} and/or its primary specification in RFC 2396 should
88
 * note some differences.
89
 *
90
 * <h3>Uniform Hierarchical Syntax</h3>
91
 *
92
 * <p>RFC 3986 unifies the older ideas of "hierarchical" and "opaque" URIs into a single generic
93
 * syntax. What RFC 2396 called an opaque "scheme-specific part" is always broken out by RFC 3986
94
 * into an authority and path hierarchy, followed by query and fragment components. Accordingly,
95
 * this class has only getters for those components but no {@link
96
 * java.net.URI#getSchemeSpecificPart()} analog.
97
 *
98
 * <p>The RFC 3986 definition of path is now more liberal to accommodate this:
99
 *
100
 * <ul>
101
 *   <li>Path doesn't have to start with a slash. For example, the path of <code>
102
 *       urn:isbn:978-1492082798</code> is <code>isbn:978-1492082798</code> even though it doesn't
103
 *       look much like a file system path.
104
 *   <li>The path can now be empty. So Android's <code>
105
 *       intent:#Intent;action=MAIN;category=LAUNCHER;end</code> is now a valid {@link Uri}. Even
106
 *       the scheme-only <code>about:</code> is now valid.
107
 * </ul>
108
 *
109
 * <p>The uniform syntax always understands what follows a '?' to be a query string. For example,
110
 * <code>mailto:me@example.com?subject=foo</code> now has a query component whereas RFC 2396
111
 * considered everything after the <code>mailto:</code> scheme to be opaque.
112
 *
113
 * <p>Same goes for fragment. <code>data:image/png;...#xywh=0,0,10,10</code> now has a fragment
114
 * whereas RFC 2396 considered everything after the scheme to be opaque.
115
 *
116
 * <h3>Uniform Authority Syntax</h3>
117
 *
118
 * <p>RFC 2396 tried to guess if an authority was a "server" (host:port) or "registry-based"
119
 * (arbitrary string) based on its contents. RFC 3986 expects every authority to look like
120
 * [userinfo@]host[:port] and loosens the definition of a "host" to accommodate. Accordingly, this
121
 * class has no equivalent to {@link java.net.URI#parseServerAuthority()} -- authority was parsed
122
 * into its components and checked for validity when the {@link Uri} was created.
123
 *
124
 * <h3>Other Specific Differences</h3>
125
 *
126
 * <p>RFC 2396 does not allow underscores in a host name, meaning {@link java.net.URI} switches to
127
 * opaque mode when it sees one. {@link Uri} does allow underscores in host, to accommodate
128
 * registries other than DNS. So <code>http://my_site.com:8080/index.html</code> now parses as a
129
 * host, port and path rather than a single opaque scheme-specific part.
130
 *
131
 * <p>{@link Uri} strictly *requires* square brackets in the query string and fragment to be
132
 * percent-encoded whereas RFC 2396 merely recommended doing so.
133
 *
134
 * <p>Other URx classes are "liberal in what they accept and strict in what they produce." {@link
135
 * Uri#parse(String)} and {@link Uri#create(String)}, however, are strict in what they accept and
136
 * transparent when asked to reproduce it via {@link Uri#toString()}. The former policy may be
137
 * appropriate for parsing user input or web content, but this class is meant for gRPC clients,
138
 * servers and plugins like name resolvers where human error at runtime is less likely and best
139
 * detected early. {@link java.net.URI#create(String)} is similarly strict, which makes migration
140
 * easy, except for the server/registry-based ambiguity addressed by {@link
141
 * java.net.URI#parseServerAuthority()}.
142
 *
143
 * <p>{@link java.net.URI} and {@link Uri} both support IPv6 literals in square brackets as defined
144
 * by RFC 2732.
145
 *
146
 * <p>{@link java.net.URI} supports IPv6 scope IDs but accepts and emits a non-standard syntax.
147
 * {@link Uri} implements the newer RFC 6874, which percent encodes scope IDs and the % delimiter
148
 * itself. RFC 9844 claims to obsolete RFC 6874 because web browsers would not support it. This
149
 * class implements RFC 6874 anyway, mostly to avoid creating a barrier to migration away from
150
 * {@link java.net.URI}.
151
 *
152
 * <p>Some URI components, e.g. scheme, are required while others may or may not be present, e.g.
153
 * authority. {@link Uri} is careful to preserve the distinction between an absent string component
154
 * (getter returns null) and one with an empty value (getter returns ""). {@link java.net.URI} makes
155
 * this distinction too, *except* when it comes to the authority and host components: {@link
156
 * java.net.URI#getAuthority()} and {@link java.net.URI#getHost()} return null when an authority is
157
 * absent, e.g. <code>file:/path</code> as expected. But these methods surprisingly also return null
158
 * when the authority is the empty string, e.g.<code>file:///path</code>. {@link Uri}'s getters
159
 * correctly return null and "" in these cases, respectively, as one would expect.
160
 */
161
@Internal
162
public final class Uri {
163
  // Components are stored percent-encoded, just as originally parsed for transparent parse/toString
164
  // round-tripping.
165
  private final String scheme; // != null since we don't support relative references.
166
  @Nullable private final String userInfo;
167
  @Nullable private final String host;
168
  @Nullable private final String port;
169
  private final String path; // In RFC 3986, path is always defined (but can be empty).
170
  @Nullable private final String query;
171
  @Nullable private final String fragment;
172

173
  private Uri(Builder builder) {
1✔
174
    this.scheme = checkNotNull(builder.scheme, "scheme");
1✔
175
    this.userInfo = builder.userInfo;
1✔
176
    this.host = builder.host;
1✔
177
    this.port = builder.port;
1✔
178
    this.path = builder.path;
1✔
179
    this.query = builder.query;
1✔
180
    this.fragment = builder.fragment;
1✔
181

182
    // Checks common to the parse() and Builder code paths.
183
    if (hasAuthority()) {
1✔
184
      if (!path.isEmpty() && !path.startsWith("/")) {
1✔
185
        throw new IllegalArgumentException("Has authority -- Non-empty path must start with '/'");
1✔
186
      }
187
    } else {
188
      if (path.startsWith("//")) {
1✔
189
        throw new IllegalArgumentException("No authority -- Path cannot start with '//'");
1✔
190
      }
191
    }
192
  }
1✔
193

194
  /**
195
   * Parses a URI from its string form.
196
   *
197
   * @throws URISyntaxException if 's' is not a valid RFC 3986 URI.
198
   */
199
  public static Uri parse(String s) throws URISyntaxException {
200
    try {
201
      return create(s);
1✔
202
    } catch (IllegalArgumentException e) {
1✔
203
      throw new URISyntaxException(s, e.getMessage());
1✔
204
    }
205
  }
206

207
  /**
208
   * Creates a URI from a string assumed to be valid.
209
   *
210
   * <p>Useful for defining URI constants in code. Not for user input.
211
   *
212
   * @throws IllegalArgumentException if 's' is not a valid RFC 3986 URI.
213
   */
214
  public static Uri create(String s) {
215
    Builder builder = new Builder();
1✔
216
    int i = 0;
1✔
217
    final int n = s.length();
1✔
218

219
    // 3.1. Scheme: Look for a ':' before '/', '?', or '#'.
220
    int schemeColon = -1;
1✔
221
    for (; i < n; ++i) {
1✔
222
      char c = s.charAt(i);
1✔
223
      if (c == ':') {
1✔
224
        schemeColon = i;
1✔
225
        break;
1✔
226
      } else if (c == '/' || c == '?' || c == '#') {
1✔
227
        break;
1✔
228
      }
229
    }
230
    if (schemeColon < 0) {
1✔
231
      throw new IllegalArgumentException("Missing required scheme.");
1✔
232
    }
233
    builder.setRawScheme(s.substring(0, schemeColon));
1✔
234

235
    // 3.2. Authority. Look for '//' then keep scanning until '/', '?', or '#'.
236
    i = schemeColon + 1;
1✔
237
    if (i + 1 < n && s.charAt(i) == '/' && s.charAt(i + 1) == '/') {
1✔
238
      // "//" just means we have an authority. Skip over it.
239
      i += 2;
1✔
240

241
      int authorityStart = i;
1✔
242
      for (; i < n; ++i) {
1✔
243
        char c = s.charAt(i);
1✔
244
        if (c == '/' || c == '?' || c == '#') {
1✔
245
          break;
1✔
246
        }
247
      }
248
      builder.setRawAuthority(s.substring(authorityStart, i));
1✔
249
    }
250

251
    // 3.3. Path: Whatever is left before '?' or '#'.
252
    int pathStart = i;
1✔
253
    for (; i < n; ++i) {
1✔
254
      char c = s.charAt(i);
1✔
255
      if (c == '?' || c == '#') {
1✔
256
        break;
1✔
257
      }
258
    }
259
    builder.setRawPath(s.substring(pathStart, i));
1✔
260

261
    // 3.4. Query, if we stopped at '?'.
262
    if (i < n && s.charAt(i) == '?') {
1✔
263
      i++; // Skip '?'
1✔
264
      int queryStart = i;
1✔
265
      for (; i < n; ++i) {
1✔
266
        char c = s.charAt(i);
1✔
267
        if (c == '#') {
1✔
268
          break;
1✔
269
        }
270
      }
271
      builder.setRawQuery(s.substring(queryStart, i));
1✔
272
    }
273

274
    // 3.5. Fragment, if we stopped at '#'.
275
    if (i < n && s.charAt(i) == '#') {
1✔
276
      ++i; // Skip '#'
1✔
277
      builder.setRawFragment(s.substring(i));
1✔
278
    }
279

280
    return builder.build();
1✔
281
  }
282

283
  private static int findPortStartColon(String authority, int hostStart) {
284
    for (int i = authority.length() - 1; i >= hostStart; --i) {
1✔
285
      char c = authority.charAt(i);
1✔
286
      if (c == ':') {
1✔
287
        return i;
1✔
288
      }
289
      if (c == ']') {
1✔
290
        // Hit the end of IP-literal. Any further colon is inside it and couldn't indicate a port.
291
        break;
1✔
292
      }
293
      if (!digitChars.get(c)) {
1✔
294
        // Found a non-digit, non-colon, non-bracket.
295
        // This means there is no valid port (e.g. host is "example.com")
296
        break;
1✔
297
      }
298
    }
299
    return -1;
1✔
300
  }
301

302
  // Checks a raw path for validity and parses it into segments. Let 'out' be null to just validate.
303
  private static void parseAssumedUtf8PathIntoSegments(
304
      String path, ImmutableList.Builder<String> out) {
305
    // Skip the first slash so it doesn't count as an empty segment at the start.
306
    // (e.g., "/a" -> ["a"], not ["", "a"])
307
    int start = path.startsWith("/") ? 1 : 0;
1✔
308

309
    for (int i = start; i < path.length(); ) {
1✔
310
      int nextSlash = path.indexOf('/', i);
1✔
311
      String segment;
312
      if (nextSlash >= 0) {
1✔
313
        // Typical segment case (e.g., "foo" in "/foo/bar").
314
        segment = path.substring(i, nextSlash);
1✔
315
        i = nextSlash + 1;
1✔
316
      } else {
317
        // Final segment case (e.g., "bar" in "/foo/bar").
318
        segment = path.substring(i);
1✔
319
        i = path.length();
1✔
320
      }
321
      if (out != null) {
1✔
322
        out.add(percentDecodeAssumedUtf8(segment));
1✔
323
      } else {
324
        checkPercentEncodedArg(segment, "path segment", pChars);
1✔
325
      }
326
    }
1✔
327

328
    // RFC 3986 says a trailing slash creates a final empty segment.
329
    // (e.g., "/foo/" -> ["foo", ""])
330
    if (path.endsWith("/") && out != null) {
1✔
331
      out.add("");
1✔
332
    }
333
  }
1✔
334

335
  /** Returns the scheme of this URI. */
336
  public String getScheme() {
337
    return scheme;
1✔
338
  }
339

340
  /**
341
   * Returns the percent-decoded "Authority" component of this URI, or null if not present.
342
   *
343
   * <p>NB: This method's decoding is lossy -- It only exists for compatibility with {@link
344
   * java.net.URI}. Prefer {@link #getRawAuthority()} or work instead with authority in terms of its
345
   * individual components ({@link #getUserInfo()}, {@link #getHost()} and {@link #getPort()}). The
346
   * problem with getAuthority() is that it returns the delimited concatenation of the percent-
347
   * decoded userinfo, host and port components. But both userinfo and host can contain the '@'
348
   * character, which becomes indistinguishable from the userinfo/host delimiter after decoding. For
349
   * example, URIs <code>scheme://x@y%40z</code> and <code>scheme://x%40y@z</code> have different
350
   * userinfo and host components but getAuthority() returns "x@y@z" for both of them.
351
   *
352
   * <p>NB: This method assumes the "host" component was encoded as UTF-8, as mandated by RFC 3986.
353
   * This method also assumes the "user information" part of authority was encoded as UTF-8,
354
   * although RFC 3986 doesn't specify an encoding.
355
   *
356
   * <p>Decoding errors are indicated by a {@code '\u005CuFFFD'} unicode replacement character in
357
   * the output. Callers who want to detect and handle errors in some other way should call {@link
358
   * #getRawAuthority()}, {@link #percentDecode(CharSequence)}, then decode the bytes for
359
   * themselves.
360
   */
361
  @Nullable
362
  public String getAuthority() {
363
    return percentDecodeAssumedUtf8(getRawAuthority());
1✔
364
  }
365

366
  private boolean hasAuthority() {
367
    return host != null;
1✔
368
  }
369

370
  /**
371
   * Returns the "authority" component of this URI in its originally parsed, possibly
372
   * percent-encoded form.
373
   */
374
  @Nullable
375
  public String getRawAuthority() {
376
    if (hasAuthority()) {
1✔
377
      StringBuilder sb = new StringBuilder();
1✔
378
      appendAuthority(sb);
1✔
379
      return sb.toString();
1✔
380
    }
381
    return null;
1✔
382
  }
383

384
  private void appendAuthority(StringBuilder sb) {
385
    if (userInfo != null) {
1✔
386
      sb.append(userInfo).append('@');
1✔
387
    }
388
    if (host != null) {
1✔
389
      sb.append(host);
1✔
390
    }
391
    if (port != null) {
1✔
392
      sb.append(':').append(port);
1✔
393
    }
394
  }
1✔
395

396
  /**
397
   * Returns the percent-decoded "User Information" component of this URI, or null if not present.
398
   *
399
   * <p>NB: This method *assumes* this component was encoded as UTF-8, although RFC 3986 doesn't
400
   * specify an encoding.
401
   *
402
   * <p>Decoding errors are indicated by a {@code '\u005CuFFFD'} unicode replacement character in
403
   * the output. Callers who want to detect and handle errors in some other way should call {@link
404
   * #getRawUserInfo()}, {@link #percentDecode(CharSequence)}, then decode the bytes for themselves.
405
   */
406
  @Nullable
407
  public String getUserInfo() {
408
    return percentDecodeAssumedUtf8(userInfo);
1✔
409
  }
410

411
  /**
412
   * Returns the "User Information" component of this URI in its originally parsed, possibly
413
   * percent-encoded form.
414
   */
415
  @Nullable
416
  public String getRawUserInfo() {
417
    return userInfo;
1✔
418
  }
419

420
  /**
421
   * Returns the percent-decoded "host" component of this URI, or null if not present.
422
   *
423
   * <p>This method assumes the host was encoded as UTF-8, as mandated by RFC 3986.
424
   *
425
   * <p>Decoding errors are indicated by a {@code '\u005CuFFFD'} unicode replacement character in
426
   * the output. Callers who want to detect and handle errors in some other way should call {@link
427
   * #getRawHost()}, {@link #percentDecode(CharSequence)}, then decode the bytes for themselves.
428
   */
429
  @Nullable
430
  public String getHost() {
431
    return percentDecodeAssumedUtf8(host);
1✔
432
  }
433

434
  /**
435
   * Returns the host component of this URI in its originally parsed, possibly percent-encoded form.
436
   */
437
  @Nullable
438
  public String getRawHost() {
439
    return host;
1✔
440
  }
441

442
  /** Returns the "port" component of this URI, or -1 if empty or not present. */
443
  public int getPort() {
444
    return port != null && !port.isEmpty() ? Integer.parseInt(port) : -1;
1✔
445
  }
446

447
  /** Returns the raw port component of this URI in its originally parsed form. */
448
  @Nullable
449
  public String getRawPort() {
450
    return port;
1✔
451
  }
452

453
  /**
454
   * Returns the (possibly empty) percent-decoded "path" component of this URI.
455
   *
456
   * <p>NB: This method *assumes* the path was encoded as UTF-8, although RFC 3986 doesn't specify
457
   * an encoding.
458
   *
459
   * <p>Decoding errors are indicated by a {@code '\u005CuFFFD'} unicode replacement character in
460
   * the output. Callers who want to detect and handle errors in some other way should call {@link
461
   * #getRawPath()}, {@link #percentDecode(CharSequence)}, then decode the bytes for themselves.
462
   *
463
   * <p>NB: Prefer {@link #getPathSegments()} because this method's decoding is lossy. For example,
464
   * consider these (different) URIs:
465
   *
466
   * <ul>
467
   *   <li>file:///home%2Ffolder/my%20file
468
   *   <li>file:///home/folder/my%20file
469
   * </ul>
470
   *
471
   * <p>Calling getPath() on each returns the same string: <code>/home/folder/my file</code>. You
472
   * can't tell whether the second '/' character is part of the first path segment or separates the
473
   * first and second path segments. This method only exists to ease migration from {@link
474
   * java.net.URI}.
475
   */
476
  public String getPath() {
477
    return percentDecodeAssumedUtf8(path);
1✔
478
  }
479

480
  /**
481
   * Returns this URI's path as a list of path segments not including the '/' segment delimiters.
482
   *
483
   * <p>Prefer this method over {@link #getPath()} because it preserves the distinction between
484
   * segment separators and literal '/'s within a path segment.
485
   *
486
   * <p>A trailing '/' delimiter in the path results in the empty string as the last element in the
487
   * returned list. For example, <code>file://localhost/foo/bar/</code> has path segments <code>
488
   * ["foo", "bar", ""]</code>
489
   *
490
   * <p>A leading '/' delimiter cannot be detected using this method. For example, both <code>
491
   * dns:example.com</code> and <code>dns:///example.com</code> have the same list of path segments:
492
   * <code>["example.com"]</code>. Use {@link #isPathAbsolute()} or {@link #isPathRootless()} to
493
   * distinguish these cases.
494
   *
495
   * <p>The returned list is immutable.
496
   */
497
  public List<String> getPathSegments() {
498
    // Returned list must be immutable but we intentionally keep guava out of the public API.
499
    ImmutableList.Builder<String> segmentsBuilder = ImmutableList.builder();
1✔
500
    parseAssumedUtf8PathIntoSegments(path, segmentsBuilder);
1✔
501
    return segmentsBuilder.build();
1✔
502
  }
503

504
  /**
505
   * Returns true iff this URI's path component starts with a path segment (rather than the '/'
506
   * segment delimiter).
507
   *
508
   * <p>The path of an RFC 3986 URI is either empty, absolute (starts with the '/' segment
509
   * delimiter) or rootless (starts with a path segment). For example, <code>tel:+1-206-555-1212
510
   * </code>, <code>mailto:me@example.com</code> and <code>urn:isbn:978-1492082798</code> all have
511
   * rootless paths. <code>mailto:%2Fdev%2Fnull@example.com</code> is also rootless because its
512
   * percent-encoded slashes are not segment delimiters but rather part of the first and only path
513
   * segment.
514
   *
515
   * <p>Contrast rootless paths with absolute ones (see {@link #isPathAbsolute()}.
516
   */
517
  public boolean isPathRootless() {
518
    return !path.isEmpty() && !path.startsWith("/");
1✔
519
  }
520

521
  /**
522
   * Returns true iff this URI's path component starts with the '/' segment delimiter (rather than a
523
   * path segment).
524
   *
525
   * <p>The path of an RFC 3986 URI is either empty, absolute (starts with the '/' segment
526
   * delimiter) or rootless (starts with a path segment). For example, <code>file:///resume.txt
527
   * </code>, <code>file:/resume.txt</code> and <code>file://localhost/</code> all have absolute
528
   * paths while <code>tel:+1-206-555-1212</code>'s path is not absolute. <code>
529
   * mailto:%2Fdev%2Fnull@example.com</code> is also not absolute because its percent-encoded
530
   * slashes are not segment delimiters but rather part of the first and only path segment.
531
   *
532
   * <p>Contrast absolute paths with rootless ones (see {@link #isPathRootless()}.
533
   *
534
   * <p>NB: The term "absolute" has two different meanings in RFC 3986 which are easily confused.
535
   * This method tests for a property of this URI's path component. Contrast with {@link
536
   * #isAbsolute()} which tests the URI itself for a different property.
537
   */
538
  public boolean isPathAbsolute() {
539
    return path.startsWith("/");
1✔
540
  }
541

542
  /**
543
   * Returns the path component of this URI in its originally parsed, possibly percent-encoded form.
544
   */
545
  public String getRawPath() {
546
    return path;
1✔
547
  }
548

549
  /**
550
   * Returns the percent-decoded "query" component of this URI, or null if not present.
551
   *
552
   * <p>NB: This method assumes the query was encoded as UTF-8, although RFC 3986 doesn't specify an
553
   * encoding.
554
   *
555
   * <p>Decoding errors are indicated by a {@code '\u005CuFFFD'} unicode replacement character in
556
   * the output. Callers who want to detect and handle errors in some other way should call {@link
557
   * #getRawQuery()}, {@link #percentDecode(CharSequence)}, then decode the bytes for themselves.
558
   */
559
  @Nullable
560
  public String getQuery() {
561
    return percentDecodeAssumedUtf8(query);
1✔
562
  }
563

564
  /**
565
   * Returns the query component of this URI in its originally parsed, possibly percent-encoded
566
   * form, without any leading '?' character.
567
   */
568
  @Nullable
569
  public String getRawQuery() {
570
    return query;
1✔
571
  }
572

573
  /**
574
   * Returns the percent-decoded "fragment" component of this URI, or null if not present.
575
   *
576
   * <p>NB: This method assumes the fragment was encoded as UTF-8, although RFC 3986 doesn't specify
577
   * an encoding.
578
   *
579
   * <p>Decoding errors are indicated by a {@code '\u005CuFFFD'} unicode replacement character in
580
   * the output. Callers who want to detect and handle errors in some other way should call {@link
581
   * #getRawFragment()}, {@link #percentDecode(CharSequence)}, then decode the bytes for themselves.
582
   */
583
  @Nullable
584
  public String getFragment() {
585
    return percentDecodeAssumedUtf8(fragment);
1✔
586
  }
587

588
  /**
589
   * Returns the fragment component of this URI in its original, possibly percent-encoded form, and
590
   * without any leading '#' character.
591
   */
592
  @Nullable
593
  public String getRawFragment() {
594
    return fragment;
1✔
595
  }
596

597
  /**
598
   * {@inheritDoc}
599
   *
600
   * <p>If this URI was created by {@link #parse(String)} or {@link #create(String)}, then the
601
   * returned string will match that original input exactly.
602
   */
603
  @Override
604
  public String toString() {
605
    // https://datatracker.ietf.org/doc/html/rfc3986#section-5.3
606
    StringBuilder sb = new StringBuilder();
1✔
607
    sb.append(scheme).append(':');
1✔
608
    if (hasAuthority()) {
1✔
609
      sb.append("//");
1✔
610
      appendAuthority(sb);
1✔
611
    }
612
    sb.append(path);
1✔
613
    if (query != null) {
1✔
614
      sb.append('?').append(query);
1✔
615
    }
616
    if (fragment != null) {
1✔
617
      sb.append('#').append(fragment);
1✔
618
    }
619
    return sb.toString();
1✔
620
  }
621

622
  /**
623
   * Returns true iff this URI has a scheme and an authority/path hierarchy, but no fragment.
624
   *
625
   * <p>All instances of {@link Uri} are RFC 3986 URIs, not "relative references", so this method is
626
   * equivalent to {@code getFragment() == null}. It mostly exists for compatibility with {@link
627
   * java.net.URI}.
628
   */
629
  public boolean isAbsolute() {
630
    return scheme != null && fragment == null;
1✔
631
  }
632

633
  /**
634
   * {@inheritDoc}
635
   *
636
   * <p>Two instances of {@link Uri} are equal if and only if they have the same string
637
   * representation, which RFC 3986 calls "Simple String Comparison" (6.2.1). Callers with a higher
638
   * layer expectation of equality (e.g. <code>http://some%2Dhost:80/foo/./bar.txt</code> ~= <code>
639
   * http://some-host/foo/bar.txt</code>) will experience false negatives.
640
   */
641
  @Override
642
  public boolean equals(Object otherObj) {
643
    if (!(otherObj instanceof Uri)) {
1✔
644
      return false;
1✔
645
    }
646
    Uri other = (Uri) otherObj;
1✔
647
    return Objects.equals(scheme, other.scheme)
1✔
648
        && Objects.equals(userInfo, other.userInfo)
1✔
649
        && Objects.equals(host, other.host)
1✔
650
        && Objects.equals(port, other.port)
1✔
651
        && Objects.equals(path, other.path)
1✔
652
        && Objects.equals(query, other.query)
1✔
653
        && Objects.equals(fragment, other.fragment);
1✔
654
  }
655

656
  @Override
657
  public int hashCode() {
658
    return Objects.hash(scheme, userInfo, host, port, path, query, fragment);
1✔
659
  }
660

661
  /** Returns a new Builder initialized with the fields of this URI. */
662
  public Builder toBuilder() {
663
    return new Builder(this);
1✔
664
  }
665

666
  /** Creates a new {@link Builder} with all fields uninitialized or set to their default values. */
667
  public static Builder newBuilder() {
668
    return new Builder();
1✔
669
  }
670

671
  /** Builder for {@link Uri}. */
672
  public static final class Builder {
673
    private String scheme;
674
    private String path = "";
1✔
675
    private String query;
676
    private String fragment;
677
    private String userInfo;
678
    private String host;
679
    private String port;
680

681
    private Builder() {}
1✔
682

683
    Builder(Uri prototype) {
1✔
684
      this.scheme = prototype.scheme;
1✔
685
      this.userInfo = prototype.userInfo;
1✔
686
      this.host = prototype.host;
1✔
687
      this.port = prototype.port;
1✔
688
      this.path = prototype.path;
1✔
689
      this.query = prototype.query;
1✔
690
      this.fragment = prototype.fragment;
1✔
691
    }
1✔
692

693
    /**
694
     * Sets the scheme, e.g. "https", "dns" or "xds".
695
     *
696
     * <p>This field is required.
697
     *
698
     * @return this, for fluent building
699
     * @throws IllegalArgumentException if the scheme is invalid.
700
     */
701
    @CanIgnoreReturnValue
702
    public Builder setScheme(String scheme) {
703
      return setRawScheme(scheme.toLowerCase(Locale.ROOT));
1✔
704
    }
705

706
    @CanIgnoreReturnValue
707
    Builder setRawScheme(String scheme) {
708
      if (scheme.isEmpty() || !alphaChars.get(scheme.charAt(0))) {
1✔
709
        throw new IllegalArgumentException("Scheme must start with an alphabetic char");
1✔
710
      }
711
      for (int i = 0; i < scheme.length(); i++) {
1✔
712
        char c = scheme.charAt(i);
1✔
713
        if (!schemeChars.get(c)) {
1✔
714
          throw new IllegalArgumentException("Invalid character in scheme at index " + i);
1✔
715
        }
716
      }
717
      this.scheme = scheme;
1✔
718
      return this;
1✔
719
    }
720

721
    /**
722
     * Specifies the new URI's path component as a string of zero or more '/' delimited segments.
723
     *
724
     * <p>Path segments can consist of any string of codepoints. Codepoints that can't be encoded
725
     * literally will be percent-encoded for you.
726
     *
727
     * <p>If a URI contains an authority component, then the path component must either be empty or
728
     * begin with a slash ("/") character. If a URI does not contain an authority component, then
729
     * the path cannot begin with two slash characters ("//").
730
     *
731
     * <p>This method interprets all '/' characters in 'path' as segment delimiters. If any of your
732
     * segments contain literal '/' characters, call {@link #setRawPath(String)} instead.
733
     *
734
     * <p>See <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.3">RFC 3986 3.3</a>
735
     * for more.
736
     *
737
     * <p>This field is required but can be empty (its default value).
738
     *
739
     * @param path the new path
740
     * @return this, for fluent building
741
     */
742
    @CanIgnoreReturnValue
743
    public Builder setPath(String path) {
744
      checkArgument(path != null, "Path can be empty but not null");
1✔
745
      this.path = percentEncode(path, pCharsAndSlash);
1✔
746
      return this;
1✔
747
    }
748

749
    /**
750
     * Specifies the new URI's path component as a string of zero or more '/' delimited segments.
751
     *
752
     * <p>Path segments can consist of any string of codepoints but the caller must first percent-
753
     * encode anything other than RFC 3986's "pchar" character class using UTF-8.
754
     *
755
     * <p>If a URI contains an authority component, then the path component must either be empty or
756
     * begin with a slash ("/") character. If a URI does not contain an authority component, then
757
     * the path cannot begin with two slash characters ("//").
758
     *
759
     * <p>This method interprets all '/' characters in 'path' as segment delimiters. If any of your
760
     * segments contain literal '/' characters, you must percent-encode them.
761
     *
762
     * <p>See <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.3">RFC 3986 3.3</a>
763
     * for more.
764
     *
765
     * <p>This field is required but can be empty (its default value).
766
     *
767
     * @param path the new path, a string consisting of characters from "pchar"
768
     * @return this, for fluent building
769
     */
770
    @CanIgnoreReturnValue
771
    public Builder setRawPath(String path) {
772
      checkArgument(path != null, "Path can be empty but not null");
1✔
773
      parseAssumedUtf8PathIntoSegments(path, null);
1✔
774
      this.path = path;
1✔
775
      return this;
1✔
776
    }
777

778
    /**
779
     * Specifies the query component of the new URI (not including the leading '?').
780
     *
781
     * <p>Query can contain any string of codepoints. Codepoints that can't be encoded literally
782
     * will be percent-encoded for you as UTF-8.
783
     *
784
     * <p>This field is optional.
785
     *
786
     * @param query the new query component, or null to clear this field
787
     * @return this, for fluent building
788
     */
789
    @CanIgnoreReturnValue
790
    public Builder setQuery(@Nullable String query) {
791
      this.query = percentEncode(query, queryChars);
1✔
792
      return this;
1✔
793
    }
794

795
    @CanIgnoreReturnValue
796
    Builder setRawQuery(String query) {
797
      checkPercentEncodedArg(query, "query", queryChars);
1✔
798
      this.query = query;
1✔
799
      return this;
1✔
800
    }
801

802
    /**
803
     * Specifies the fragment component of the new URI (not including the leading '#').
804
     *
805
     * <p>The fragment can contain any string of codepoints. Codepoints that can't be encoded
806
     * literally will be percent-encoded for you as UTF-8.
807
     *
808
     * <p>This field is optional.
809
     *
810
     * @param fragment the new fragment component, or null to clear this field
811
     * @return this, for fluent building
812
     */
813
    @CanIgnoreReturnValue
814
    public Builder setFragment(@Nullable String fragment) {
815
      this.fragment = percentEncode(fragment, fragmentChars);
1✔
816
      return this;
1✔
817
    }
818

819
    @CanIgnoreReturnValue
820
    Builder setRawFragment(String fragment) {
821
      checkPercentEncodedArg(fragment, "fragment", fragmentChars);
1✔
822
      this.fragment = fragment;
1✔
823
      return this;
1✔
824
    }
825

826
    /**
827
     * Set the "user info" component of the new URI, e.g. "username:password", not including the
828
     * trailing '@' character.
829
     *
830
     * <p>User info can contain any string of codepoints. Codepoints that can't be encoded literally
831
     * will be percent-encoded for you as UTF-8.
832
     *
833
     * <p>This field is optional.
834
     *
835
     * @param userInfo the new "user info" component, or null to clear this field
836
     * @return this, for fluent building
837
     */
838
    @CanIgnoreReturnValue
839
    public Builder setUserInfo(@Nullable String userInfo) {
840
      this.userInfo = percentEncode(userInfo, userInfoChars);
1✔
841
      return this;
1✔
842
    }
843

844
    @CanIgnoreReturnValue
845
    Builder setRawUserInfo(String userInfo) {
846
      checkPercentEncodedArg(userInfo, "userInfo", userInfoChars);
1✔
847
      this.userInfo = userInfo;
1✔
848
      return this;
1✔
849
    }
850

851
    /**
852
     * Specifies the "host" component of the new URI in its "registered name" form (usually DNS),
853
     * e.g. "server.com".
854
     *
855
     * <p>The registered name can contain any string of codepoints. Codepoints that can't be encoded
856
     * literally will be percent-encoded for you as UTF-8.
857
     *
858
     * <p>This field is optional.
859
     *
860
     * @param regName the new host component in "registered name" form, or null to clear this field
861
     * @return this, for fluent building
862
     */
863
    @CanIgnoreReturnValue
864
    public Builder setHost(@Nullable String regName) {
865
      if (regName != null) {
1✔
866
        regName = regName.toLowerCase(Locale.ROOT);
1✔
867
        regName = percentEncode(regName, regNameChars);
1✔
868
      }
869
      this.host = regName;
1✔
870
      return this;
1✔
871
    }
872

873
    /**
874
     * Specifies the "host" component of the new URI as an IP address.
875
     *
876
     * <p>This field is optional.
877
     *
878
     * @param addr the new "host" component in InetAddress form, or null to clear this field
879
     * @return this, for fluent building
880
     */
881
    @CanIgnoreReturnValue
882
    public Builder setHost(@Nullable InetAddress addr) {
883
      this.host = addr != null ? toUriString(addr) : null;
1✔
884
      return this;
1✔
885
    }
886

887
    private static String toUriString(InetAddress addr) {
888
      // InetAddresses.toUriString(addr) is almost enough but neglects RFC 6874 percent encoding.
889
      String inetAddrStr = InetAddresses.toUriString(addr);
1✔
890
      int percentIndex = inetAddrStr.indexOf('%');
1✔
891
      if (percentIndex < 0) {
1✔
892
        return inetAddrStr;
1✔
893
      }
894

895
      String scope = inetAddrStr.substring(percentIndex, inetAddrStr.length() - 1);
1✔
896
      return inetAddrStr.substring(0, percentIndex) + percentEncode(scope, unreservedChars) + "]";
1✔
897
    }
898

899
    @CanIgnoreReturnValue
900
    Builder setRawHost(String host) {
901
      if (host.startsWith("[") && host.endsWith("]")) {
1✔
902
        // IP-literal: Guava's isUriInetAddress() is almost enough but it doesn't check the scope.
903
        int percentIndex = host.indexOf('%');
1✔
904
        if (percentIndex > 0) {
1✔
905
          String scope = host.substring(percentIndex, host.length() - 1);
1✔
906
          checkPercentEncodedArg(scope, "scope", unreservedChars);
1✔
907
        }
908
      }
909
      // IP-literal validation is complicated so we delegate it to Guava. We use this particular
910
      // method of InetAddresses because it doesn't try to match interfaces on the local machine.
911
      // (The validity of a URI should be the same no matter which machine does the parsing.)
912
      // TODO(jdcormie): IPFuture
913
      if (!InetAddresses.isUriInetAddress(host)) {
1✔
914
        // Must be a "registered name".
915
        checkPercentEncodedArg(host, "host", regNameChars);
1✔
916
      }
917
      this.host = host;
1✔
918
      return this;
1✔
919
    }
920

921
    /**
922
     * Specifies the "port" component of the new URI, e.g. "8080".
923
     *
924
     * <p>The port can be any non-negative integer. A negative value represents "no port".
925
     *
926
     * <p>This field is optional.
927
     *
928
     * @param port the new "port" component, or -1 to clear this field
929
     * @return this, for fluent building
930
     */
931
    @CanIgnoreReturnValue
932
    public Builder setPort(int port) {
933
      this.port = port < 0 ? null : Integer.toString(port);
1✔
934
      return this;
1✔
935
    }
936

937
    @CanIgnoreReturnValue
938
    Builder setRawPort(String port) {
939
      if (port != null && !port.isEmpty()) {
1✔
940
        try {
941
          Integer.parseInt(port); // Result unused.
1✔
942
        } catch (NumberFormatException e) {
×
943
          throw new IllegalArgumentException("Invalid port", e);
×
944
        }
1✔
945
      }
946
      this.port = port;
1✔
947
      return this;
1✔
948
    }
949

950
    /**
951
     * Specifies the userinfo, host and port URI components all at once using a single string.
952
     *
953
     * <p>This setter is "raw" in the sense that special characters in userinfo and host must be
954
     * passed in percent-encoded. See <a
955
     * href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.2">RFC 3986 3.2</a> for the set
956
     * of characters allowed in each component of an authority.
957
     *
958
     * <p>There's no "cooked" method to set authority like for other URI components because
959
     * authority is a *compound* URI component whose userinfo, host and port components are
960
     * delimited with special characters '@' and ':'. But the first two of those components can
961
     * themselves contain these delimiters so we need percent-encoding to parse them unambiguously.
962
     *
963
     * @param authority an RFC 3986 authority string that will be used to set userinfo, host and
964
     *     port, or null to clear all three of those components
965
     */
966
    @CanIgnoreReturnValue
967
    public Builder setRawAuthority(@Nullable String authority) {
968
      if (authority == null) {
1✔
969
        setUserInfo(null);
1✔
970
        setHost((String) null);
1✔
971
        setPort(-1);
1✔
972
      } else {
973
        // UserInfo. Easy because '@' cannot appear unencoded inside userinfo or host.
974
        int userInfoEnd = authority.indexOf('@');
1✔
975
        if (userInfoEnd >= 0) {
1✔
976
          setRawUserInfo(authority.substring(0, userInfoEnd));
1✔
977
        } else {
978
          setUserInfo(null);
1✔
979
        }
980

981
        // Host/Port.
982
        int hostStart = userInfoEnd >= 0 ? userInfoEnd + 1 : 0;
1✔
983
        int portStartColon = findPortStartColon(authority, hostStart);
1✔
984
        if (portStartColon < 0) {
1✔
985
          setRawHost(authority.substring(hostStart));
1✔
986
          setPort(-1);
1✔
987
        } else {
988
          setRawHost(authority.substring(hostStart, portStartColon));
1✔
989
          setRawPort(authority.substring(portStartColon + 1));
1✔
990
        }
991
      }
992
      return this;
1✔
993
    }
994

995
    /** Builds a new instance of {@link Uri} as specified by the setters. */
996
    public Uri build() {
997
      checkState(scheme != null, "Missing required scheme.");
1✔
998
      if (host == null) {
1✔
999
        checkState(port == null, "Cannot set port without host.");
1✔
1000
        checkState(userInfo == null, "Cannot set userInfo without host.");
1✔
1001
      }
1002
      return new Uri(this);
1✔
1003
    }
1004
  }
1005

1006
  /**
1007
   * Decodes a string of characters in the range [U+0000, U+007F] to bytes.
1008
   *
1009
   * <p>Each percent-encoded sequence (e.g. "%F0" or "%2a", as defined by RFC 3986 2.1) is decoded
1010
   * to the octet it encodes. Other characters are decoded to their code point's single byte value.
1011
   * A literal % character must be encoded as %25.
1012
   *
1013
   * @throws IllegalArgumentException if 's' contains characters out of range or invalid percent
1014
   *     encoding sequences.
1015
   */
1016
  public static ByteBuffer percentDecode(CharSequence s) {
1017
    // This is large enough because each input character needs *at most* one byte of output.
1018
    ByteBuffer outBuf = ByteBuffer.allocate(s.length());
1✔
1019
    percentDecode(s, "input", null, outBuf);
1✔
1020
    outBuf.flip();
1✔
1021
    return outBuf;
1✔
1022
  }
1023

1024
  private static void percentDecode(
1025
      CharSequence s, String what, BitSet allowedChars, ByteBuffer outBuf) {
1026
    for (int i = 0; i < s.length(); i++) {
1✔
1027
      char c = s.charAt(i);
1✔
1028
      if (c == '%') {
1✔
1029
        if (i + 2 >= s.length()) {
1✔
1030
          throw new IllegalArgumentException(
1✔
1031
              "Invalid percent-encoding at index " + i + " of " + what + ": " + s);
1032
        }
1033
        int h1 = Character.digit(s.charAt(i + 1), 16);
1✔
1034
        int h2 = Character.digit(s.charAt(i + 2), 16);
1✔
1035
        if (h1 == -1 || h2 == -1) {
1✔
1036
          throw new IllegalArgumentException(
1✔
1037
              "Invalid hex digit in " + what + " at index " + i + " of: " + s);
1038
        }
1039
        if (outBuf != null) {
1✔
1040
          outBuf.put((byte) (h1 << 4 | h2));
1✔
1041
        }
1042
        i += 2;
1✔
1043
      } else if (allowedChars == null || allowedChars.get(c)) {
1✔
1044
        if (outBuf != null) {
1✔
1045
          outBuf.put((byte) c);
1✔
1046
        }
1047
      } else {
1048
        throw new IllegalArgumentException("Invalid character in " + what + " at index " + i);
1✔
1049
      }
1050
    }
1051
  }
1✔
1052

1053
  @Nullable
1054
  private static String percentDecodeAssumedUtf8(@Nullable String s) {
1055
    if (s == null || s.indexOf('%') == -1) {
1✔
1056
      return s;
1✔
1057
    }
1058

1059
    ByteBuffer utf8Bytes = percentDecode(s);
1✔
1060
    try {
1061
      return StandardCharsets.UTF_8
1✔
1062
          .newDecoder()
1✔
1063
          .onMalformedInput(CodingErrorAction.REPLACE)
1✔
1064
          .onUnmappableCharacter(CodingErrorAction.REPLACE)
1✔
1065
          .decode(utf8Bytes)
1✔
1066
          .toString();
1✔
1067
    } catch (CharacterCodingException e) {
×
1068
      throw new VerifyException(e); // Should not happen in REPLACE mode.
×
1069
    }
1070
  }
1071

1072
  @Nullable
1073
  private static String percentEncode(String s, BitSet allowedCodePoints) {
1074
    if (s == null) {
1✔
1075
      return null;
1✔
1076
    }
1077
    CharsetEncoder encoder =
1✔
1078
        StandardCharsets.UTF_8
1079
            .newEncoder()
1✔
1080
            .onMalformedInput(CodingErrorAction.REPORT)
1✔
1081
            .onUnmappableCharacter(CodingErrorAction.REPORT);
1✔
1082
    ByteBuffer utf8Bytes;
1083
    try {
1084
      utf8Bytes = encoder.encode(CharBuffer.wrap(s));
1✔
1085
    } catch (MalformedInputException e) {
1✔
1086
      throw new IllegalArgumentException("Malformed input", e); // Must be a broken surrogate pair.
1✔
1087
    } catch (CharacterCodingException e) {
×
1088
      throw new VerifyException(e); // Should not happen when encoding to UTF-8.
×
1089
    }
1✔
1090

1091
    StringBuilder sb = new StringBuilder();
1✔
1092
    while (utf8Bytes.hasRemaining()) {
1✔
1093
      int b = 0xff & utf8Bytes.get();
1✔
1094
      if (allowedCodePoints.get(b)) {
1✔
1095
        sb.append((char) b);
1✔
1096
      } else {
1097
        sb.append('%');
1✔
1098
        sb.append(hexDigitsByVal[(b & 0xF0) >> 4]);
1✔
1099
        sb.append(hexDigitsByVal[b & 0x0F]);
1✔
1100
      }
1101
    }
1✔
1102
    return sb.toString();
1✔
1103
  }
1104

1105
  private static void checkPercentEncodedArg(String s, String what, BitSet allowedChars) {
1106
    percentDecode(s, what, allowedChars, null);
1✔
1107
  }
1✔
1108

1109
  // See UriTest for how these were computed from the ABNF constants in RFC 3986.
1110
  static final BitSet digitChars = BitSet.valueOf(new long[] {0x3ff000000000000L});
1✔
1111
  static final BitSet alphaChars = BitSet.valueOf(new long[] {0L, 0x7fffffe07fffffeL});
1✔
1112
  // scheme        = ALPHA *( ALPHA / DIGIT / "+" / "-" / "." )
1113
  static final BitSet schemeChars =
1✔
1114
      BitSet.valueOf(new long[] {0x3ff680000000000L, 0x7fffffe07fffffeL});
1✔
1115
  // unreserved  = ALPHA / DIGIT / "-" / "." / "_" / "~"
1116
  static final BitSet unreservedChars =
1✔
1117
      BitSet.valueOf(new long[] {0x3ff600000000000L, 0x47fffffe87fffffeL});
1✔
1118
  // gen-delims    = ":" / "/" / "?" / "#" / "[" / "]" / "@"
1119
  static final BitSet genDelimsChars =
1✔
1120
      BitSet.valueOf(new long[] {0x8400800800000000L, 0x28000001L});
1✔
1121
  // sub-delims    = "!" / "$" / "&" / "'" / "(" / ")" / "*" / "+" / "," / ";" / "="
1122
  static final BitSet subDelimsChars = BitSet.valueOf(new long[] {0x28001fd200000000L});
1✔
1123
  // reserved      = gen-delims / sub-delims
1124
  static final BitSet reservedChars = BitSet.valueOf(new long[] {0xac009fda00000000L, 0x28000001L});
1✔
1125
  // reg-name      = *( unreserved / pct-encoded / sub-delims )
1126
  static final BitSet regNameChars =
1✔
1127
      BitSet.valueOf(new long[] {0x2bff7fd200000000L, 0x47fffffe87fffffeL});
1✔
1128
  // userinfo      = *( unreserved / pct-encoded / sub-delims / ":" )
1129
  static final BitSet userInfoChars =
1✔
1130
      BitSet.valueOf(new long[] {0x2fff7fd200000000L, 0x47fffffe87fffffeL});
1✔
1131
  // pchar         = unreserved / pct-encoded / sub-delims / ":" / "@"
1132
  static final BitSet pChars =
1✔
1133
      BitSet.valueOf(new long[] {0x2fff7fd200000000L, 0x47fffffe87ffffffL});
1✔
1134
  static final BitSet pCharsAndSlash =
1✔
1135
      BitSet.valueOf(new long[] {0x2fffffd200000000L, 0x47fffffe87ffffffL});
1✔
1136
  //  query         = *( pchar / "/" / "?" )
1137
  static final BitSet queryChars =
1✔
1138
      BitSet.valueOf(new long[] {0xafffffd200000000L, 0x47fffffe87ffffffL});
1✔
1139
  // fragment      = *( pchar / "/" / "?" )
1140
  static final BitSet fragmentChars = queryChars;
1✔
1141

1142
  private static final char[] hexDigitsByVal = "0123456789ABCDEF".toCharArray();
1✔
1143
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc