Skip to content

api: Delete Uri's get/setQuery and replace with a safer approach#12772

Open
jdcormie wants to merge 2 commits intogrpc:masterfrom
jdcormie:grpc-query-editor
Open

api: Delete Uri's get/setQuery and replace with a safer approach#12772
jdcormie wants to merge 2 commits intogrpc:masterfrom
jdcormie:grpc-query-editor

Conversation

@jdcormie
Copy link
Copy Markdown
Member

Allows you to work with URL-encoded query parameters as a layer on top of io.grpc.Uri.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a small utility layer for working with application/x-www-form-urlencoded query parameters on top of io.grpc.Uri, including the ability to round-trip raw query strings while still offering decoded key/value access.

Changes:

  • Introduces io.grpc.QueryParameters (parser + mutable container + entry model) for URL-encoded query parameters.
  • Extends Uri.Builder#setRawQuery(...) to be public and to support clearing the query by passing null.
  • Adds unit tests covering QueryParameters behavior and Uri.Builder#setRawQuery(...).

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
api/src/main/java/io/grpc/Uri.java Makes Builder#setRawQuery public and allows null to clear the field.
api/src/main/java/io/grpc/QueryParameters.java New internal parser/mutable container for x-www-form-urlencoded query parameters.
api/src/test/java/io/grpc/UriTest.java Adds coverage for setRawQuery and clearing via null.
api/src/test/java/io/grpc/QueryParametersTest.java New unit tests for parsing, encoding round-trips, removal, and Uri integration.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread api/src/main/java/io/grpc/QueryParameters.java Outdated
Comment thread api/src/main/java/io/grpc/QueryParams.java
Comment thread api/src/test/java/io/grpc/QueryParametersTest.java Outdated
Comment thread api/src/main/java/io/grpc/QueryParams.java
Comment thread api/src/main/java/io/grpc/QueryParams.java Outdated
@jdcormie jdcormie force-pushed the grpc-query-editor branch from dc37b9a to a0ca758 Compare May 1, 2026 00:05
@jdcormie jdcormie changed the title api: Add a parser/editor for URL encoded query parameters api: Delete Uri's get/setQuery and replace with a safer approach May 1, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +53 to +63
/** Creates a new, empty {@code QueryParameters} instance. */
public QueryParams() {}

/**
* Parses a raw query string into a {@code QueryParameters} instance.
*
* <p>The input is split on {@code '&'} and each parameter is parsed as either a key/value pair
* (if it contains an equals sign) or a "lone" key (if it does not).
*
* @param rawQuery the raw query component to parse, must not be null
* @return a new {@code QueryParameters} instance containing the parsed parameters
Comment on lines +50 to +51
private static final String UTF_8 = "UTF-8";
private final List<Entry> entries = new ArrayList<>();
* <p>The query component can only be provided in its raw form. That’s because virtually
* everyone uses query as a container for structured data, with some additional layer of
* encoding not present in RFC-3986. Like 'application/x-www-form-urlencoded', which encodes
* key/ value pairs like so: <code>?k1=v1&k2=v+2</code>. The encoding of these containers always
Comment on lines +81 to +84
QueryParams.Entry first = params.getLast("");
// getLast returns the LAST one
assertEquals("", first.getKey());
assertEquals("", first.getValue());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants