Skip to content

Commit

Permalink
Added logic to trim uri input.
Browse files Browse the repository at this point in the history
Signed-off-by: AWSHurneyt <[email protected]>
  • Loading branch information
AWSHurneyt committed Sep 14, 2023
1 parent 397cf0c commit e4ac7d5
Showing 1 changed file with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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(':', '"', '+', '\\', '|', '?', '#', '>', '<', ' ')
Expand Down Expand Up @@ -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()
}

Expand Down

0 comments on commit e4ac7d5

Please sign in to comment.