Skip to content
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

#4925 - Guard for empty strings in html response writer #4926

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,25 +19,25 @@
import java.io.IOException;
import java.io.Writer;
import java.util.LinkedList;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import javax.el.ValueExpression;
import javax.faces.FacesException;
import javax.faces.component.UIComponent;
import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;
import javax.faces.context.ResponseWriter;
import javax.faces.render.Renderer;

import com.sun.faces.RIConstants;
import com.sun.faces.config.WebConfiguration;
import com.sun.faces.config.WebConfiguration.BooleanWebContextInitParameter;
import com.sun.faces.io.FastStringWriter;
import com.sun.faces.util.HtmlUtils;
import com.sun.faces.util.MessageUtils;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import javax.el.ValueExpression;
import javax.faces.context.ExternalContext;
import javax.faces.render.Renderer;


/**
Expand Down Expand Up @@ -162,8 +162,8 @@ public class HtmlResponseWriter extends ResponseWriter {
private static final char[] ESCAPEDSTART= ("<"+BREAKCDATA+"![").toCharArray();
private static final char[] ESCAPEDEND= ("]"+BREAKCDATA+"]>").toCharArray();

private static final int CLOSEBRACKET = (int)']';
private static final int LT = (int)'<';
private static final int CLOSEBRACKET = ']';
private static final int LT = '<';

static final Pattern CDATA_START_SLASH_SLASH;

Expand Down Expand Up @@ -957,7 +957,7 @@ public void writeText(Object text, String componentPropertyName)
String textStr = text.toString();

if (dontEscape) {
if (writingCdata) {
if (writingCdata && !textStr.isEmpty()) {
writeUnescapedCData(textStr.toCharArray(), 0, textStr.length());
} else {
writer.write(textStr);
Expand Down Expand Up @@ -1432,6 +1432,11 @@ private void flushBuffer() throws IOException {
* When writing un-escaped CDATA, "]]>" sequence still has to be escaped by breaking CDATA block.
*/
private void writeUnescapedCData(char[] cbuf, int offset, int length) throws IOException {
// zero char case
if (length == 0) {
return;
}

// single char case
if (length == 1) {
if (cbuf[offset] == ']') {
Expand Down