Skip to content

Commit

Permalink
chore: URL encode query parameter part when creating dynamic endpoint…
Browse files Browse the repository at this point in the history
… components

- Allows to use special characters in query parameters such as "#" for instance
  • Loading branch information
christophd committed Nov 8, 2024
1 parent 940264f commit 133951c
Showing 1 changed file with 13 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import java.lang.reflect.Method;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.HashMap;
import java.util.LinkedHashMap;
Expand All @@ -30,8 +32,8 @@
import org.citrusframework.exceptions.CitrusRuntimeException;
import org.citrusframework.spi.ReferenceResolverAware;
import org.citrusframework.util.ReflectionHelper;
import org.citrusframework.util.TypeConversionUtils;
import org.citrusframework.util.StringUtils;
import org.citrusframework.util.TypeConversionUtils;

/**
* Default endpoint component reads component name from endpoint uri and parses parameters from uri using
Expand Down Expand Up @@ -59,7 +61,7 @@ public AbstractEndpointComponent(String name) {
@Override
public Endpoint createEndpoint(String endpointUri, TestContext context) {
try {
URI uri = new URI(endpointUri);
URI uri = new URI(resolveEndpointUri(endpointUri));
String path = uri.getSchemeSpecificPart();

if (path.startsWith("//")) {
Expand Down Expand Up @@ -202,6 +204,15 @@ protected String getParameterString(Map<String, String> parameters,
return paramString.toString();
}

private static String resolveEndpointUri(String endpointUri) {
if (endpointUri.contains("?")) {
String[] tokens = endpointUri.split("\\?", 2);
return tokens[0] + "?" + URLEncoder.encode(tokens[1], StandardCharsets.UTF_8);
} else {
return endpointUri;
}
}

/**
* Create endpoint instance from uri resource and parameters.
* @param resourcePath
Expand Down

0 comments on commit 133951c

Please sign in to comment.