Skip to content
Open
Show file tree
Hide file tree
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
4 changes: 4 additions & 0 deletions core/src/java/org/jdom2/input/sax/SAXBuilderEngine.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
import org.xml.sax.XMLReader;

import org.jdom2.Document;
import org.jdom2.IllegalDataException;
import org.jdom2.JDOMException;
import org.jdom2.JDOMFactory;
import org.jdom2.input.JDOMParseException;
Expand Down Expand Up @@ -235,6 +236,9 @@ public Document build(final InputSource in)
} catch (final SAXException e) {
throw new JDOMParseException("Error in building: " +
e.getMessage(), e, saxHandler.getDocument());
} catch (final IllegalDataException e) {
throw new JDOMParseException("Error in building: " +
e.getMessage(), e, saxHandler.getDocument());
} finally {
// Explicitly nullify the handler to encourage GC
// It's a stack var so this shouldn't be necessary, but it
Expand Down
15 changes: 15 additions & 0 deletions test/src/java/org/jdom2/test/cases/input/TestSAXBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,12 @@ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
import org.jdom2.DefaultJDOMFactory;
import org.jdom2.Document;
import org.jdom2.EntityRef;
import org.jdom2.IllegalDataException;
import org.jdom2.JDOMConstants;
import org.jdom2.JDOMException;
import org.jdom2.JDOMFactory;
import org.jdom2.UncheckedJDOMFactory;
import org.jdom2.input.JDOMParseException;
import org.jdom2.input.SAXBuilder;
import org.jdom2.input.sax.BuilderErrorHandler;
import org.jdom2.input.sax.SAXEngine;
Expand Down Expand Up @@ -1035,6 +1037,19 @@ public void testBuildReader() {
}
}

@Test
public void testXML11IllegalCharacterIsReportedAsParseException()
throws JDOMException, IOException {
final String xml = "<?xml version=\"1.1\" encoding=\"UTF-8\"?>" +
"<root>char:&#x05;</root>";
try {
new SAXBuilder().build(new CharArrayReader(xml.toCharArray()));
failNoException(JDOMParseException.class);
} catch (final JDOMParseException e) {
assertTrue(e.getCause() instanceof IllegalDataException);
}
}

@Test
public void testBuildReaderString() {
char[] chars = testxml.toCharArray();
Expand Down