api: Delete Uri's get/setQuery and replace with a safer approach#12772
Open
jdcormie wants to merge 2 commits intogrpc:masterfrom
Open
api: Delete Uri's get/setQuery and replace with a safer approach#12772jdcormie wants to merge 2 commits intogrpc:masterfrom
jdcormie wants to merge 2 commits intogrpc:masterfrom
Conversation
7e5aa56 to
dc37b9a
Compare
Contributor
There was a problem hiding this comment.
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 passingnull. - Adds unit tests covering
QueryParametersbehavior andUri.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.
dc37b9a to
a0ca758
Compare
a0ca758 to
3411fdc
Compare
Contributor
There was a problem hiding this comment.
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()); |
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.
Allows you to work with URL-encoded query parameters as a layer on top of io.grpc.Uri.