-
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); |
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.