From 56fab0d48d4933a9ef560d06858aa40c21495390 Mon Sep 17 00:00:00 2001 From: Rohit Awate Date: Wed, 1 Aug 2018 17:55:26 +0530 Subject: [PATCH] Fix parameter appending logic --- pom.xml | 2 +- .../controllers/DashboardController.java | 28 +++++++++++++------ .../everest/misc/EverestUtilities.java | 5 ++++ 3 files changed, 25 insertions(+), 10 deletions(-) diff --git a/pom.xml b/pom.xml index 90e4854..adf7c3c 100644 --- a/pom.xml +++ b/pom.xml @@ -20,7 +20,7 @@ 4.0.0 com.rohitawate Everest - Alpha-1.2 + Alpha-1.3 jar UTF-8 diff --git a/src/main/java/com/rohitawate/everest/controllers/DashboardController.java b/src/main/java/com/rohitawate/everest/controllers/DashboardController.java index 2617f76..57f8ba3 100644 --- a/src/main/java/com/rohitawate/everest/controllers/DashboardController.java +++ b/src/main/java/com/rohitawate/everest/controllers/DashboardController.java @@ -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 paramsControllers; - private List 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())); } /** diff --git a/src/main/java/com/rohitawate/everest/misc/EverestUtilities.java b/src/main/java/com/rohitawate/everest/misc/EverestUtilities.java index 5d92450..0b373cc 100644 --- a/src/main/java/com/rohitawate/everest/misc/EverestUtilities.java +++ b/src/main/java/com/rohitawate/everest/misc/EverestUtilities.java @@ -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); + } }