Imagine you have the following XML input:
<message priority="info"><![CDATA[ expected:<[[D/0]]]]><![CDATA[> but was:<[null]>]]></message>
this would be a legal XML representing the following string:
expected:<[[D/0]]> but was: <[null]>
now when SAXHandler.characters() gets called, it would try to merge subsequent CDATAs, and call setText() which would fail with:
Caused by: org.jdom.IllegalDataException: The data " expected:<[[D/0]]> but was:<[null]>" is not legal for a JDOM CDATA section: CDATA cannot internally contain a CDATA ending delimiter (]]>).
at org.apache.xerces.parsers.AbstractSAXParser.endElement(Unknown Source)
It's not a nice fix, but its an easy workaround.
fix for merging CDATAs producing an ending tag ]]> in the resulting C…
Good catch. And appreciate the patch... but I am not particularly happy with the fix.... I think there's an issue in it:
if (previousCDATA != inCDATA || (ch[start] == '>' || (ch[start] == ']' && ch[start] == '>') ))
(ch[start] == ']' && ch[start] == '>') cannot possibly be true....
The situation is that the 'real' data contains a closing CDATA tag ']]>' and this is 'split' between two 'real' CDATA sections... so, the fix really needs to span what's been seen already, and what's just arrived...
I realize that the bug is real, but this fix is incomplete... If you want to have another stab at it, feel free, and I'll pull it in, but as it stands it's not ready. Otherwise, I'll take a look at it myself in a day or two.
Oh, you are right, it was meant like this:
ch[start] == ']' && ch[start+1] == '>'
I updated the pull request, but you don't have to use it, a better fix should be possible. I guess a CDATA could get broken by more than just a closing tag, i.e. "]]>".
I am going to contemplate this issue for a bit. I think I may have an alternative approach which is more reliable. I will have to take the time to play with the code though.
Just so you are aware, this issue is not a problem in JDOM 2.x , and I strongly recommend you upgrade to that. It is unlikely that there will be another JDOM 1.x release any time soon.
Issue #124 - Split CDATA sections causing trouble in JDOM 1.x. Add te…
…st case to 2.x anyway - even though code works.