Skip to content

Conversation

@dkkplk
Copy link

@dkkplk dkkplk commented Jan 23, 2026

No description provided.

Copy link

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

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 using URI + URIBuilder and (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.

client.testStep("step2");
client.testStop(TestResultFactory.createFailure("Just because", new Throwable("Yikes")));
assertEquals(client.getReportUrl(), "link");
assertEquals(client.getReportUrl(), "/link");
Copy link

Copilot AI Jan 23, 2026

Choose a reason for hiding this comment

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

The test sets the executionReportUrl capability to the relative string "link" but asserts that getReportUrl() returns "/link". Unless getReportUrl intentionally normalizes relative URLs by adding a leading slash, this assertion looks inconsistent with the input and may fail/flap. Consider either returning "/link" from the mock capability or asserting the unmodified relative value.

Suggested change
assertEquals(client.getReportUrl(), "/link");
assertEquals(client.getReportUrl(), "link");

Copilot uses AI. Check for mistakes.
Comment on lines +229 to +247
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], "");
}
}
}

Copy link

Copilot AI Jan 23, 2026

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.

Suggested change
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);

Copilot uses AI. Check for mistakes.
Comment on lines +229 to +247
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], "");
}
}
}

Copy link

Copilot AI Jan 23, 2026

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.

Suggested change
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);

Copilot uses AI. Check for mistakes.
Comment on lines +251 to +252
throw new ReportiumException("Failed to create report URL", e);
}
Copy link

Copilot AI Jan 23, 2026

Choose a reason for hiding this comment

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

Previously this method returned String.valueOf(value) even if the capability value wasn't a valid URI. With the new parsing, malformed/partially-formed values will now throw ReportiumException, which is a behavior change for callers. If strict validation isn't required, consider falling back to returning the raw capability string on URISyntaxException (or only applying encoding when the URL parses cleanly).

Suggested change
throw new ReportiumException("Failed to create report URL", e);
}
// Fallback to previous behavior: return the raw capability string
return String.valueOf(value);

Copilot uses AI. Check for mistakes.
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