From e4ac7d5338aead2cbd61d539b4f9f52bd31addf3 Mon Sep 17 00:00:00 2001 From: AWSHurneyt Date: Thu, 14 Sep 2023 10:50:46 -0700 Subject: [PATCH] Added logic to trim uri input. Signed-off-by: AWSHurneyt --- .../commons/alerting/model/ClusterMetricsInput.kt | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/main/kotlin/org/opensearch/commons/alerting/model/ClusterMetricsInput.kt b/src/main/kotlin/org/opensearch/commons/alerting/model/ClusterMetricsInput.kt index ed522ef7..87e12f13 100644 --- a/src/main/kotlin/org/opensearch/commons/alerting/model/ClusterMetricsInput.kt +++ b/src/main/kotlin/org/opensearch/commons/alerting/model/ClusterMetricsInput.kt @@ -12,6 +12,7 @@ import org.opensearch.core.xcontent.ToXContent import org.opensearch.core.xcontent.XContentBuilder import org.opensearch.core.xcontent.XContentParser import java.io.IOException +import java.lang.StringBuilder import java.net.URI val ILLEGAL_PATH_PARAMETER_CHARACTERS = arrayOf(':', '"', '+', '\\', '|', '?', '#', '>', '<', ' ') @@ -207,11 +208,20 @@ data class ClusterMetricsInput( * @return The constructed [URI]. */ private fun constructUrlFromInputs(): URI { + val fullPath = StringBuilder() + .append(path.trim('/')) + + if (pathParams.isNotEmpty()) + fullPath + .append('/') + .append(pathParams.trim('/')) + val uriBuilder = URIBuilder() .setScheme(SUPPORTED_SCHEME) .setHost(SUPPORTED_HOST) .setPort(SUPPORTED_PORT) - .setPath(path + pathParams) + .setPath(fullPath.toString()) + return uriBuilder.build() }