Fix parameter appending logic

This commit is contained in:
Rohit Awate 2018-08-01 17:55:26 +05:30
parent 45b757c7c8
commit 56fab0d48d
No known key found for this signature in database
GPG key ID: 1051D7B79CF2EE25
3 changed files with 25 additions and 10 deletions

View file

@ -20,7 +20,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.rohitawate</groupId>
<artifactId>Everest</artifactId>
<version>Alpha-1.2</version>
<version>Alpha-1.3</version>
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

View file

@ -27,6 +27,7 @@ import com.rohitawate.everest.exceptions.RedirectException;
import com.rohitawate.everest.exceptions.UnreliableResponseException;
import com.rohitawate.everest.format.FormatterFactory;
import com.rohitawate.everest.logging.LoggingService;
import com.rohitawate.everest.misc.EverestUtilities;
import com.rohitawate.everest.misc.Services;
import com.rohitawate.everest.misc.ThemeManager;
import com.rohitawate.everest.models.requests.DELETERequest;
@ -93,7 +94,6 @@ public class DashboardController implements Initializable {
private JFXSnackbar snackbar;
private final String[] httpMethods = {"GET", "POST", "PUT", "DELETE", "PATCH"};
private List<StringKeyValueFieldController> paramsControllers;
private List<String> appendedParams;
private RequestManager requestManager;
private HeaderTabController headerTabController;
private BodyTabController bodyTabController;
@ -151,7 +151,6 @@ public class DashboardController implements Initializable {
paramsControllers = new ArrayList<>();
paramsCountProperty = new SimpleIntegerProperty(0);
appendedParams = new ArrayList<>();
addParamField(); // Adds a blank param field
bodyTab.disableProperty().bind(
@ -446,7 +445,6 @@ public class DashboardController implements Initializable {
private void prettifyResponseBody(String body, String contentType) {
showLayer(ResponseLayer.RESPONSE);
visualizerTab.setDisable(true);
visualizer.clear();
try {
String simplifiedContentType;
@ -522,18 +520,30 @@ public class DashboardController implements Initializable {
@FXML
private void appendParams() {
String pair, key, value;
StringBuilder url = new StringBuilder();
url.append(addressField.getText().split("\\?")[0]);
boolean addedQuestionMark = false;
String key, value;
for (StringKeyValueFieldController controller : paramsControllers) {
if (controller.isChecked()) {
if (!addedQuestionMark) {
url.append("?");
addedQuestionMark = true;
} else {
url.append("&");
}
key = controller.getHeader().getKey();
value = controller.getHeader().getValue();
pair = key + value;
if (!appendedParams.contains(pair)) {
addressField.appendText("?" + key + "=" + value + "&");
appendedParams.add(pair);
}
url.append(key);
url.append("=");
url.append(value);
}
}
addressField.clear();
addressField.setText(EverestUtilities.encodeURL(url.toString()));
}
/**

View file

@ -18,6 +18,7 @@ package com.rohitawate.everest.misc;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.google.common.net.UrlEscapers;
public class EverestUtilities {
public static ObjectMapper jsonMapper;
@ -36,4 +37,8 @@ public class EverestUtilities {
public static String trimString(String input) {
return input.replaceAll("\"", "");
}
public static String encodeURL(String url) {
return UrlEscapers.urlFragmentEscaper().escape(url);
}
}