-
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?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -11,12 +11,15 @@ | |||||||||||||||||||||||||||||||||||||||
| import com.perfecto.reportium.test.result.TestResult; | ||||||||||||||||||||||||||||||||||||||||
| import org.apache.commons.lang3.StringUtils; | ||||||||||||||||||||||||||||||||||||||||
| import org.apache.commons.lang3.tuple.Pair; | ||||||||||||||||||||||||||||||||||||||||
| import org.apache.http.client.utils.URIBuilder; | ||||||||||||||||||||||||||||||||||||||||
| import org.openqa.selenium.HasCapabilities; | ||||||||||||||||||||||||||||||||||||||||
| import org.openqa.selenium.JavascriptExecutor; | ||||||||||||||||||||||||||||||||||||||||
| import org.openqa.selenium.WebDriver; | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| import java.util.*; | ||||||||||||||||||||||||||||||||||||||||
| import java.util.logging.Logger; | ||||||||||||||||||||||||||||||||||||||||
| import java.net.URI; | ||||||||||||||||||||||||||||||||||||||||
| import java.net.URISyntaxException; | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| import static com.perfecto.reportium.model.util.ExecutionContextPopulator.EQUALS; | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
|
|
@@ -218,8 +221,35 @@ public String getReportUrl() { | |||||||||||||||||||||||||||||||||||||||
| if (value == null) { | ||||||||||||||||||||||||||||||||||||||||
| return null; | ||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| try { | ||||||||||||||||||||||||||||||||||||||||
| String reportUrl = String.valueOf(value); | ||||||||||||||||||||||||||||||||||||||||
| URI originalUri = new URI(reportUrl); | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| 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], ""); | ||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
|
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], ""); | |
| } | |
| } | |
| } | |
| URIBuilder uriBuilder = new URIBuilder(originalUri); |
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.
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).
| throw new ReportiumException("Failed to create report URL", e); | |
| } | |
| // Fallback to previous behavior: return the raw capability string | |
| return String.valueOf(value); |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -19,6 +19,7 @@ | |||||
| * Test case for {@link PerfectoReportiumClient} | ||||||
| */ | ||||||
| public class PerfectoReportiumClientTest { | ||||||
| public static final String EXPECTED_REPORT_URL = "https://tenant.reporting.perfectomobile.com/library?externalId%5B0%5D=32f76d03"; | ||||||
|
|
||||||
| /** | ||||||
| * Marker interface for EasyMock to simulate a RemoteWebDriver. | ||||||
|
|
@@ -48,7 +49,7 @@ public void testWebDriverInteraction() { | |||||
| client.testStep("step1"); | ||||||
| client.testStep("step2"); | ||||||
| client.testStop(TestResultFactory.createFailure("Just because", new Throwable("Yikes"))); | ||||||
| assertEquals(client.getReportUrl(), "link"); | ||||||
| assertEquals(client.getReportUrl(), "/link"); | ||||||
|
||||||
| assertEquals(client.getReportUrl(), "/link"); | |
| assertEquals(client.getReportUrl(), "link"); |
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.