FULL PRODUCT VERSION :
java version "1.6.0_10"
Java(TM) SE Runtime Environment (build 1.6.0_10-b33)
Java HotSpot(TM) Client VM (build 11.0-b15, mixed mode, sharing)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows XP [Version 5.1.2600]
A DESCRIPTION OF THE PROBLEM :
When using SJSXP for reading in XML with doctype definitions, the doctype definition is truncated after exactly 64 characters.
For example, reading in this content:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html><body>Hello.</body></html>
results in a DTD event containing only the document type declaration <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "
The implementation in XMLDocumentScannerImpl.getDTDDecl() is the cause for the problem. Regardless of the DTD size, always 32 is provided as last argument for the fDTDDeck.append method.
fDTDDecl.append(((Entity.ScannedEntity)entity).ch,fStartPos , fEndPos-fStartPos);
needs to be fixed with
fDTDDecl.append(((Entity.ScannedEntity)entity).ch,fStartPos , ((Entity.ScannedEntity)entity).position);
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
see test case.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
DTD event document type declaration is
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
ACTUAL -
DTD event document type declaration is
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "
(ends after exactly 64 characters)
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import java.io.ByteArrayInputStream;
import java.io.FileNotFoundException;
import javax.xml.stream.XMLEventReader;
import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.events.DTD;
import javax.xml.stream.events.XMLEvent;
import org.junit.Test;
public class DTDDeclTest {
private static XMLInputFactory inputFactory;
/**
* Example DTD which is longer than 64 characters.
*/
private static final String TOO_LONG_DOCTYPE =
"<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">";
/**
* Example DTD which is shorter than 64 characters.
* Don't care about the ... since {@link XMLInputFactory} is configured to not validate
* the DTD!
*/
private static final String TOO_SHORT_DOCTYPE =
"<!DOCTYPE html PUBLIC \"-//W3C//...\" \"http://...\">";
private static final String BODY = "<html><body>Hello.</body></html>";
static {
inputFactory = XMLInputFactory.newInstance();
inputFactory.setProperty(XMLInputFactory.SUPPORT_DTD, Boolean.FALSE);
inputFactory.setProperty(XMLInputFactory.IS_VALIDATING, Boolean.FALSE);
inputFactory.setProperty(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES, Boolean.FALSE);
inputFactory.setProperty(XMLInputFactory.IS_NAMESPACE_AWARE, Boolean.FALSE);
}
@Test
public void reproduceTooLongDTD() throws FileNotFoundException, XMLStreamException {
DTD dtd = process(TOO_LONG_DOCTYPE + BODY);
System.out.println(dtd.getDocumentTypeDeclaration());
assertEquals("DTD not processed as expected.",
TOO_LONG_DOCTYPE,
dtd.getDocumentTypeDeclaration());
}
@Test
public void reproduceTooShortDTD() throws FileNotFoundException, XMLStreamException {
DTD dtd = process(TOO_SHORT_DOCTYPE + BODY);
System.out.println(dtd.getDocumentTypeDeclaration());
assertEquals("DTD not processed as expected.",
TOO_SHORT_DOCTYPE,
dtd.getDocumentTypeDeclaration());
}
/**
* Returns the DTD event.
*
* @param input
* @return
* @throws XMLStreamException
* @throws FileNotFoundException
*/
private DTD process(String input) throws XMLStreamException, FileNotFoundException {
XMLEventReader reader = inputFactory.createXMLEventReader(new ByteArrayInputStream(input.getBytes()));
while (reader.hasNext()) {
XMLEvent event = reader.nextEvent();
if (XMLEvent.DTD == event.getEventType()) {
return ((DTD) event);
}
}
fail("no DTD found");
return null;
}
}
---------- END SOURCE ----------
java version "1.6.0_10"
Java(TM) SE Runtime Environment (build 1.6.0_10-b33)
Java HotSpot(TM) Client VM (build 11.0-b15, mixed mode, sharing)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows XP [Version 5.1.2600]
A DESCRIPTION OF THE PROBLEM :
When using SJSXP for reading in XML with doctype definitions, the doctype definition is truncated after exactly 64 characters.
For example, reading in this content:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html><body>Hello.</body></html>
results in a DTD event containing only the document type declaration <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "
The implementation in XMLDocumentScannerImpl.getDTDDecl() is the cause for the problem. Regardless of the DTD size, always 32 is provided as last argument for the fDTDDeck.append method.
fDTDDecl.append(((Entity.ScannedEntity)entity).ch,fStartPos , fEndPos-fStartPos);
needs to be fixed with
fDTDDecl.append(((Entity.ScannedEntity)entity).ch,fStartPos , ((Entity.ScannedEntity)entity).position);
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
see test case.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
DTD event document type declaration is
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
ACTUAL -
DTD event document type declaration is
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "
(ends after exactly 64 characters)
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import java.io.ByteArrayInputStream;
import java.io.FileNotFoundException;
import javax.xml.stream.XMLEventReader;
import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.events.DTD;
import javax.xml.stream.events.XMLEvent;
import org.junit.Test;
public class DTDDeclTest {
private static XMLInputFactory inputFactory;
/**
* Example DTD which is longer than 64 characters.
*/
private static final String TOO_LONG_DOCTYPE =
"<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">";
/**
* Example DTD which is shorter than 64 characters.
* Don't care about the ... since {@link XMLInputFactory} is configured to not validate
* the DTD!
*/
private static final String TOO_SHORT_DOCTYPE =
"<!DOCTYPE html PUBLIC \"-//W3C//...\" \"http://...\">";
private static final String BODY = "<html><body>Hello.</body></html>";
static {
inputFactory = XMLInputFactory.newInstance();
inputFactory.setProperty(XMLInputFactory.SUPPORT_DTD, Boolean.FALSE);
inputFactory.setProperty(XMLInputFactory.IS_VALIDATING, Boolean.FALSE);
inputFactory.setProperty(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES, Boolean.FALSE);
inputFactory.setProperty(XMLInputFactory.IS_NAMESPACE_AWARE, Boolean.FALSE);
}
@Test
public void reproduceTooLongDTD() throws FileNotFoundException, XMLStreamException {
DTD dtd = process(TOO_LONG_DOCTYPE + BODY);
System.out.println(dtd.getDocumentTypeDeclaration());
assertEquals("DTD not processed as expected.",
TOO_LONG_DOCTYPE,
dtd.getDocumentTypeDeclaration());
}
@Test
public void reproduceTooShortDTD() throws FileNotFoundException, XMLStreamException {
DTD dtd = process(TOO_SHORT_DOCTYPE + BODY);
System.out.println(dtd.getDocumentTypeDeclaration());
assertEquals("DTD not processed as expected.",
TOO_SHORT_DOCTYPE,
dtd.getDocumentTypeDeclaration());
}
/**
* Returns the DTD event.
*
* @param input
* @return
* @throws XMLStreamException
* @throws FileNotFoundException
*/
private DTD process(String input) throws XMLStreamException, FileNotFoundException {
XMLEventReader reader = inputFactory.createXMLEventReader(new ByteArrayInputStream(input.getBytes()));
while (reader.hasNext()) {
XMLEvent event = reader.nextEvent();
if (XMLEvent.DTD == event.getEventType()) {
return ((DTD) event);
}
}
fail("no DTD found");
return null;
}
}
---------- END SOURCE ----------