ByteXmlWriter bug
ukmtk opened this issue · 3 comments
Whilst running a test in my environment I encountered a bug in aalto-xml-0-9.11.jar.
I debugged the code and think that I discovered what the problem was.
It occurred in ByteXmlWriter.writeCharacters() called from longWriteCharacters().
I was attempting to add 4K of XML onto an existing XML document (in my case it was a soapenv body that was being built up). _outputPtr was 407 at the start of the 4K output. The first part of the 4K text was 325 characters before a newline character was encountered. I think the fault is that at this point in the code (_config..willEscapeCR()) the _outputPtr is not set to ptr! So in my case ptr was 692 but gets reset to 407. This left me with garbled output.
I tried a patched aalto-xml jar with a modified ByteXmlWriter.writeCharacters():
if (_config.willEscapeCR()) {
_outputPtr = ptr;
break;
}
this appeared to fix my issue.
It seems that my proposed fix was not entirely correct. I think the patch should read:
if (_config.willEscapeCR()) {
_outputPtr = ptr;
writeAsEntity(ch);
break;
}
@ukmtk Thank you for reporting this. I'll try to get it fixed. Would be nice to have a reproduction, but sounds like it should be easy enough to fix.
Ok, I assume I found the place and it did look like that assignment was missing, so I added it.
Hard to say if it fixes the problem but until proven otherwise I assume it does.
Fix will be in 1.0.0 to be released shortly.