-
Notifications
You must be signed in to change notification settings - Fork 88
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
Clarify behaviour of ServletResponse.setCharacterEncoding(null) #377
Comments
IMHO:
My thinking for allowing the invalid values is that you may have old/broken/weird clients that need a charset that is not recognised by the JVM. You should still be able to send it, but you would need to do the encoding manually and write it to the stream rather than using the writer. |
I think we can declare consensus for null. Invalid I'm less sure about. The Javadoc requires an IANA registered character set although I'm fairly sure Java doesn't implement all of them so the user could still provide a valid but unrecognised value. Tomcat 7.0.x behaves the way you describe. Tomcat 8.5.x behaves in line with my proposal. We have had releases with that variation for ~5 years now and I don't recall any problems. I can see the flexibility of your approach but I like the additional validation of only allowing valid character sets. I want both :). More thought required. As an aside, I'm not concerned about the security implications you mentioned as apps should be validating any client provided data before using it. |
I think we need to be a little more explicit with regards to null. It should clear even non explicitly set charsets, eg a charset from a locale. eg: response.setLocale(java.util.Locale.JAPAN);
response.setCharacterEncoding(null); will result in no charset being set. Ditto for charsets obtained from setting the content type as in: response.setContentType("text/plain;charset=utf16");
response.setCharacterEncoding(null); Also, what is the behaviour with regards to a response default character encoding set in the web.xml? Does null revert to that default or does it make it as if there is no default their either? Currently in Jetty we have the following enum: private enum EncodingFrom
{
NOT_SET,
INFERRED, // eg utf-8 for json mimetype
SET_LOCALE,
SET_CONTENT_TYPE,
SET_CHARACTER_ENCODING
} Currently we treat a I think that is reasonable behaviour, but it could be that I also agree that |
I think I have enough to work on some updated text. The summary is:
|
@markt-asf sounds good and maybe check setLocale(null) at the same time to let it use the same verbage! |
I am happy with these changes, they match what Undertow currently does (with the exception of logging). |
Signed-off-by: Mark Thomas <[email protected]>
Signed-off-by: Mark Thomas <[email protected]>
Fix #377 - clarify setCharacterEncoding(null) and related
Changes due to jakartaee/servlet#377
Changes due to jakartaee/servlet#377
The Javadoc indicates that only IANA character set names are allowed but it does not define the expected behaviour for any values that are not allowed - including
null
.Generally, I'd like to see
UnsupportedEncodingException
but that would not be a backwards compatible change so I don't see how we could do that.The question for
null
arose from Tomcat bug 64938. I can see potential use cases for allowingnull
- even if there are alternative solutions for some (all?) of those use cases.I propose we modify the Javadoc for
ServletResponse.setCharacterEncoding(null)
along the following lines:null
means behave as if no character encoding has been explicitly setThe text was updated successfully, but these errors were encountered: