Skip to content

Commit 9ef2238

Browse files
authored
Merge pull request #5734 from eclipse-ee4j/issue_5733
Fix #5733: fallback using response encoding when request encoding is
2 parents 53406f6 + 55ef1d6 commit 9ef2238

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

impl/src/main/java/com/sun/faces/application/view/MultiViewHandler.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,24 @@ public MultiViewHandler() {
108108
@Override
109109
public void initView(FacesContext context) throws FacesException {
110110
super.initView(context);
111+
112+
// Spec section 2.5.2.2 falls through to the session-based fallback when
113+
// neither <f:view contentType=charset=...> nor a request Content-Type
114+
// header charset yields an encoding. That session lookup is moot when
115+
// no session is created (e.g. stateless views or client side state saving).
116+
// When that happens, super.initView never calls setRequestCharacterEncoding
117+
// and the servlet container decodes form-data with its platform default
118+
// (often ISO-8859-1) — so a postback containing non-ASCII characters
119+
// (e.g. 'ä') can get corrupted on the way in. Default to the same encoding
120+
// that Util.getResponseEncoding() uses to render the page, so request
121+
// decoding at least matches what the page was rendered with.
122+
if (context.getExternalContext().getRequestCharacterEncoding() == null) {
123+
try {
124+
context.getExternalContext().setRequestCharacterEncoding(Util.getResponseEncoding(context));
125+
} catch (UnsupportedEncodingException e) {
126+
throw new FacesException(e);
127+
}
128+
}
111129
}
112130

113131
/**

0 commit comments

Comments
 (0)