-
Notifications
You must be signed in to change notification settings - Fork 2
url encoding changes #14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Updates getReportUrl() to return a URL with properly encoded query parameters (notably [/]), and adds coverage to validate that behavior.
Changes:
- Reworked
PerfectoReportiumClient#getReportUrl()to rebuild the URL usingURI+URIBuilderand (re)encode query parameters. - Added a unit test asserting correct encoding of query parameters in the report URL.
- Updated an existing test assertion around relative report URLs.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| reportium-java/src/main/java/com/perfecto/reportium/client/PerfectoReportiumClient.java | Rebuilds report URL via URIBuilder to apply URL encoding to query parameters. |
| reportium-java/src/test/java/com/perfecto/reportium/client/PerfectoReportiumClientTest.java | Adds test for encoded query params and adjusts an existing expected report URL. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
reportium-java/src/test/java/com/perfecto/reportium/client/PerfectoReportiumClientTest.java
Show resolved
Hide resolved
| URIBuilder uriBuilder = new URIBuilder() | ||
| .setScheme(originalUri.getScheme()) | ||
| .setHost(originalUri.getHost()) | ||
| .setPort(originalUri.getPort()) | ||
| .setPath(originalUri.getPath()); | ||
|
|
||
| // Parse and add query parameters - URIBuilder will encode them | ||
| if (originalUri.getQuery() != null) { | ||
| String[] pairs = originalUri.getQuery().split("&"); | ||
| for (String pair : pairs) { | ||
| String[] keyValue = pair.split("=", 2); | ||
| if (keyValue.length == 2) { | ||
| uriBuilder.addParameter(keyValue[0], keyValue[1]); | ||
| } else { | ||
| uriBuilder.addParameter(keyValue[0], ""); | ||
| } | ||
| } | ||
| } | ||
|
|
Copilot
AI
Jan 23, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
getQuery() returns the decoded query string, so splitting on '&' can break when a parameter value contains an encoded ampersand (%26) (it will be decoded to '&' before you split). Prefer parsing the raw query (getRawQuery) or, better, construct URIBuilder directly from the original URI/string so it handles query parsing/encoding correctly.
| URIBuilder uriBuilder = new URIBuilder() | |
| .setScheme(originalUri.getScheme()) | |
| .setHost(originalUri.getHost()) | |
| .setPort(originalUri.getPort()) | |
| .setPath(originalUri.getPath()); | |
| // Parse and add query parameters - URIBuilder will encode them | |
| if (originalUri.getQuery() != null) { | |
| String[] pairs = originalUri.getQuery().split("&"); | |
| for (String pair : pairs) { | |
| String[] keyValue = pair.split("=", 2); | |
| if (keyValue.length == 2) { | |
| uriBuilder.addParameter(keyValue[0], keyValue[1]); | |
| } else { | |
| uriBuilder.addParameter(keyValue[0], ""); | |
| } | |
| } | |
| } | |
| // Let URIBuilder parse the full original URI, including query parameters, | |
| // to avoid manual splitting of the decoded query string. | |
| URIBuilder uriBuilder = new URIBuilder(originalUri); |
| URIBuilder uriBuilder = new URIBuilder() | ||
| .setScheme(originalUri.getScheme()) | ||
| .setHost(originalUri.getHost()) | ||
| .setPort(originalUri.getPort()) | ||
| .setPath(originalUri.getPath()); | ||
|
|
||
| // Parse and add query parameters - URIBuilder will encode them | ||
| if (originalUri.getQuery() != null) { | ||
| String[] pairs = originalUri.getQuery().split("&"); | ||
| for (String pair : pairs) { | ||
| String[] keyValue = pair.split("=", 2); | ||
| if (keyValue.length == 2) { | ||
| uriBuilder.addParameter(keyValue[0], keyValue[1]); | ||
| } else { | ||
| uriBuilder.addParameter(keyValue[0], ""); | ||
| } | ||
| } | ||
| } | ||
|
|
Copilot
AI
Jan 23, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This rebuilds the URI from scheme/host/port/path only, which drops other components like fragment (#...), user-info, and any original path encoding (getPath() is decoded). If the report URL can contain these, the returned URL will be altered. Using URIBuilder(originalUri) (or URIBuilder(reportUrl)) and only adjusting encoding as needed will preserve all components.
| URIBuilder uriBuilder = new URIBuilder() | |
| .setScheme(originalUri.getScheme()) | |
| .setHost(originalUri.getHost()) | |
| .setPort(originalUri.getPort()) | |
| .setPath(originalUri.getPath()); | |
| // Parse and add query parameters - URIBuilder will encode them | |
| if (originalUri.getQuery() != null) { | |
| String[] pairs = originalUri.getQuery().split("&"); | |
| for (String pair : pairs) { | |
| String[] keyValue = pair.split("=", 2); | |
| if (keyValue.length == 2) { | |
| uriBuilder.addParameter(keyValue[0], keyValue[1]); | |
| } else { | |
| uriBuilder.addParameter(keyValue[0], ""); | |
| } | |
| } | |
| } | |
| URIBuilder uriBuilder = new URIBuilder(originalUri); |
No description provided.