Survey
* Your assessment is very important for improving the work of artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the work of artificial intelligence, which forms the content of this project
[JAVASERVERFACES-3039] HtmlResponseWriter.cloneWithWriter() does
not clone writingCdata flag, cause invalid XML output Created: 30/Sep/13 Updated:
08/Jan/14 Resolved: 09/Oct/13
Status:
Project:
Component/s:
Affects
Version/s:
Fix Version/s:
Closed
javaserverfaces
renderkit
2.2.2, 2.2.3
Type:
Reporter:
Resolution:
Labels:
Remaining
Estimate:
Time Spent:
Original
Estimate:
Bug
hugh_nguyen_82
Fixed
None
Not Specified
Attachments:
changebundle.txt
cdata, htmlresponsewriter, primefaces-extension
Tags:
2.2.5
Priority:
Assignee:
Votes:
Major
Manfred Riem
0
Not Specified
Not Specified
Description
cloneWithWriter() is frequently used to create a ResponseWriter with some sort of
String / Buffer writer for optimization.
The implementation of this method in HtmlResponseWriter doesn't clone writingCdata
flag
Without writingCdata flag set correctly, the clone could write its own CDATA tags,
which corrupt XML output, if the original writer has already been writing a CDATA
section, such as in a partial response.
Actual case: when use with PrimeFaces Extension layout component.
Comments
Comment by hugh_nguyen_82 [ 30/Sep/13 ]
I added the following lines before the return line:
responseWriter.withinScript = this.withinScript;
responseWriter.withinStyle = this.withinStyle;
responseWriter.writingCdata = this.writingCdata;
responseWriter.closeStart = this.closeStart;
responseWriter.escapeIso = this.escapeIso;
responseWriter.escapeUnicode = this.escapeUnicode;
responseWriter.isScript = this.isScript;
responseWriter.isStyle = this.isStyle;
responseWriter.isCdata = this.isCdata;
responseWriter.scriptOrStyleSrc = this.scriptOrStyleSrc;
And it seems to work correctly.
Comment by Manfred Riem [ 04/Oct/13 ]
Using this particular change and running it through our test harness it fails, so I cannot accept this change withou
issues@javaserverfaces.java.net. Thanks!
Comment by hugh_nguyen_82 [ 04/Oct/13 ]
Sorry I can't figure out how to create an attachment.
Below is a test page to run with PrimeFaces 4.0, PrimeFaces Extension 1.0, and Mojarra 2.2.3.
The particular components that cause the issue to happen here are pe:layout and h:outputScript.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:c="http://java.sun.com/jsp/jstl/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui"
xmlns:pe="http://primefaces.org/ui/extensions"
xmlns:f="http://java.sun.com/jsf/core">
<h:head>
<title>Test</title>
</h:head>
<body>
<pe:layout id="theLayout">
<pe:layoutPane id="centerPane" position="center">
<h:form>
<h:commandButton value="Click Me">
<f:ajax render=":theLayout"/>
</h:commandButton>
</h:form>
<h:outputScript>var a;</h:outputScript>
</pe:layoutPane>
</pe:layout>
</body>
</html>
When you click the button, the ajax response would be as following:
<?xml version='1.0' encoding='UTF-8'?>
<partial-response id="j_id1"><changes><update id="theLayout"><![CDATA[<script id="theLayou
'widget_theLayout',{id:'theLayout',forTarget:'body',clientState:false,serverState:false,op
id="centerPane" class="ui-layout-center ui-widget-content ui-corner-all pe-layout-pane-con
<form id="j_idt5" name="j_idt5" method="post" action="/TH6/debug/test3.jsf" enctype="appli
<input type="hidden" name="j_idt5" value="j_idt5" />
<input id="j_idt5:j_idt7" type="submit" name="j_idt5:j_idt7" value="Click Me" onclick="moj
</form><script type="text/javascript">
//<![CDATA[
var a;
//]]>
</script></div>]]></update><update id="j_id1:javax.faces.ViewState:0"><![CDATA[28831292867
You see, there are nested CDATAs, and that caused malformed XML. The outer CDATA is always necessary fo
h:outputScript component.
It seems like the bug come from PrimeFaces Extension (pe:layout component), so I traced thru the LayoutRende
content to a buffer, and then pass this buffer to the parent ResponseWriter. This is quite a common technique use
The parent ResponseWriter, since it's writing a partial response, has its writingCdata flag set to true. But the clon
script content in its own CDATA section. That's how you get the nested CDATA.
So at least I think the writingCdata flag should be cloned. I tried to copy other flags too, as it seems to be the righ
the writingCdata flag?
Comment by Ed Burns [ 09/Oct/13 ]
r=edburns
Comment by Manfred Riem [ 09/Oct/13 ]
Applied to 2.2 branch,
svn commit -m "Fixes https://java.net/jira/browse/JAVASERVERFACES-3039, r=edburns, make sure the writin
Sending jsf-ri\src\main\java\com\sun\faces\renderkit\html_basic\HtmlResponseWriter.java
Sending test\unit\src\test\java\com\sun\faces\renderkit\html_basic\HtmlResponseWriterTest.java
Transmitting file data ..
Committed revision 12582.
Generated at Wed May 03 20:45:23 UTC 2017 using JIRA 6.2.3#6260sha1:63ef1d6dac3f4f4d7db4c1effd405ba38ccdc558.