8232014: Expand DTD support

Reviewed-by: lancea, dfuchs, mschoene, rhalade, aefimov
This commit is contained in:
Joe Wang 2020-02-12 18:59:58 +00:00
parent fc02d9872e
commit 697fb9e41b
3 changed files with 21 additions and 20 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2003, 2017, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2003, 2020, Oracle and/or its affiliates. All rights reserved.
*/
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
@ -63,7 +63,7 @@ import java.io.IOException;
* @author Glenn Marcy, IBM
* @author Eric Ye, IBM
*
* @LastModified: Nov 2017
* @LastModified: Feb 2020
*/
public class XMLDTDScannerImpl
extends XMLScanner
@ -608,6 +608,7 @@ implements XMLDTDScanner, XMLComponent, XMLEntityHandler {
if (fScannerState == SCANNER_STATE_END_OF_INPUT)
return;
boolean dtdEntity = name.equals("[dtd]");
// Handle end of PE
boolean reportEntity = fReportEntity;
if (name.startsWith("%")) {
@ -616,8 +617,7 @@ implements XMLDTDScanner, XMLComponent, XMLEntityHandler {
int startMarkUpDepth = popPEStack();
// throw fatalError if this entity was incomplete and
// was a freestanding decl
if(startMarkUpDepth == 0 &&
startMarkUpDepth < fMarkUpDepth) {
if (startMarkUpDepth == 0 && startMarkUpDepth < fMarkUpDepth) {
fErrorReporter.reportError(XMLMessageFormatter.XML_DOMAIN,
"ILL_FORMED_PARAMETER_ENTITY_WHEN_USED_IN_DECL",
new Object[]{ fEntityManager.fCurrentEntity.name},
@ -637,12 +637,10 @@ implements XMLDTDScanner, XMLComponent, XMLEntityHandler {
if (fEntityScanner.isExternal()) {
fExtEntityDepth--;
}
}
// call handler
boolean dtdEntity = name.equals("[dtd]");
if (fDTDHandler != null && !dtdEntity && reportEntity) {
fDTDHandler.endParameterEntity(name, null);
// call handler
if (fDTDHandler != null && reportEntity) {
fDTDHandler.endParameterEntity(name, null);
}
}
// end DTD

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2003, 2017, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2003, 2020, Oracle and/or its affiliates. All rights reserved.
*/
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
@ -67,7 +67,7 @@ import com.sun.xml.internal.stream.Entity;
* @author Eric Ye, IBM
* @author K.Venugopal SUN Microsystems
* @author Sunitha Reddy, SUN Microsystems
* @LastModified: Nov 2017
* @LastModified: Feb 2020
*/
public abstract class XMLScanner
implements XMLComponent {
@ -1239,10 +1239,10 @@ public abstract class XMLScanner
* @throws XNIException Thrown by handler to signal an error.
*/
public void endEntity(String name, Augmentations augs) throws IOException, XNIException {
// keep track of the entity depth
fEntityDepth--;
if (fEntityDepth > 0) {
fEntityDepth--;
}
} // endEntity(String)
/**

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2020, Oracle and/or its affiliates. All rights reserved.
*/
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
@ -62,7 +62,7 @@ import java.util.Random;
* @author Andy Clark, IBM
* @author Neil Graham, IBM
*
* @LastModified: Oct 2017
* @LastModified: Feb 2020
*/
public class DTDGrammar
implements XMLDTDHandler, XMLDTDContentModelHandler, EntityState, Grammar {
@ -447,9 +447,12 @@ public class DTDGrammar
* @throws XNIException Thrown by handler to signal an error.
*/
public void endParameterEntity(String name, Augmentations augs) throws XNIException {
fPEDepth--;
fReadingExternalDTD = fPEntityStack[fPEDepth];
// redundant check as this method can only be called after parsing a PE
// incomplete or truncated DTD get caught before reaching this method
if (fPEDepth > 0) {
fPEDepth--;
fReadingExternalDTD = fPEntityStack[fPEDepth];
}
} // endParameterEntity(String,Augmentations)