New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spaces in query strings get encoded as + plus signs instead of %20 #796

Closed
jamesdaily opened this Issue Nov 20, 2017 · 1 comment

Comments

Projects
None yet
2 participants
@jamesdaily
Contributor

jamesdaily commented Nov 20, 2017

In the Java client, when producing a URL, space characters in query strings get encoded as + plus signs instead of %20.

For example a search for address "123 main street" would produce a URL such as:

https://example.com/search?address=123+main+street

This is correct for application/x-www-form-urlencoded, but for non-forms based applications, it should just be RFC 3986 which uses %20 instead of + signs for spaces within query strings values.

Is it possible to configure this to use %20 instead:

https://example.com/search?address=123%20main%20street

It looks like the code responsible for the + signs is the URLEncoder.encode call here in ca.uhn.fhir.rest.client.method.HttpGetClientInvocation

private boolean addQueryParameter(StringBuilder b, boolean first, String nextKey, String nextValue) {
		boolean retVal = first;
		if (retVal) {
			b.append('?');
			retVal = false;
		} else {
			b.append('&');
		}
		try {
			b.append(URLEncoder.encode(nextKey, "UTF-8"));
			b.append('=');
			b.append(URLEncoder.encode(nextValue, "UTF-8"));
		} catch (UnsupportedEncodingException e) {
			throw new ConfigurationException("Could not find UTF-8 encoding. This shouldn't happen.", e);
		}
		return retVal;
	}
@jamesagnew

This comment has been minimized.

Owner

jamesagnew commented Nov 25, 2017

Thanks for reporting! Fix incoming.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment