提交 886efc87 编写于 作者: J joehw

8232014: Expand DTD support

Reviewed-by: lancea, dfuchs, mschoene, rhalade, aefimov
上级 6155ce48
/* /*
* 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 * Licensed to the Apache Software Foundation (ASF) under one or more
...@@ -63,7 +63,7 @@ import java.io.IOException; ...@@ -63,7 +63,7 @@ import java.io.IOException;
* @author Glenn Marcy, IBM * @author Glenn Marcy, IBM
* @author Eric Ye, IBM * @author Eric Ye, IBM
* *
* @LastModified: Nov 2017 * @LastModified: Feb 2020
*/ */
public class XMLDTDScannerImpl public class XMLDTDScannerImpl
extends XMLScanner extends XMLScanner
...@@ -608,6 +608,7 @@ implements XMLDTDScanner, XMLComponent, XMLEntityHandler { ...@@ -608,6 +608,7 @@ implements XMLDTDScanner, XMLComponent, XMLEntityHandler {
if (fScannerState == SCANNER_STATE_END_OF_INPUT) if (fScannerState == SCANNER_STATE_END_OF_INPUT)
return; return;
boolean dtdEntity = name.equals("[dtd]");
// Handle end of PE // Handle end of PE
boolean reportEntity = fReportEntity; boolean reportEntity = fReportEntity;
if (name.startsWith("%")) { if (name.startsWith("%")) {
...@@ -616,8 +617,7 @@ implements XMLDTDScanner, XMLComponent, XMLEntityHandler { ...@@ -616,8 +617,7 @@ implements XMLDTDScanner, XMLComponent, XMLEntityHandler {
int startMarkUpDepth = popPEStack(); int startMarkUpDepth = popPEStack();
// throw fatalError if this entity was incomplete and // throw fatalError if this entity was incomplete and
// was a freestanding decl // was a freestanding decl
if(startMarkUpDepth == 0 && if (startMarkUpDepth == 0 && startMarkUpDepth < fMarkUpDepth) {
startMarkUpDepth < fMarkUpDepth) {
fErrorReporter.reportError(XMLMessageFormatter.XML_DOMAIN, fErrorReporter.reportError(XMLMessageFormatter.XML_DOMAIN,
"ILL_FORMED_PARAMETER_ENTITY_WHEN_USED_IN_DECL", "ILL_FORMED_PARAMETER_ENTITY_WHEN_USED_IN_DECL",
new Object[]{ fEntityManager.fCurrentEntity.name}, new Object[]{ fEntityManager.fCurrentEntity.name},
...@@ -637,12 +637,10 @@ implements XMLDTDScanner, XMLComponent, XMLEntityHandler { ...@@ -637,12 +637,10 @@ implements XMLDTDScanner, XMLComponent, XMLEntityHandler {
if (fEntityScanner.isExternal()) { if (fEntityScanner.isExternal()) {
fExtEntityDepth--; fExtEntityDepth--;
} }
} // call handler
if (fDTDHandler != null && reportEntity) {
// call handler fDTDHandler.endParameterEntity(name, null);
boolean dtdEntity = name.equals("[dtd]"); }
if (fDTDHandler != null && !dtdEntity && reportEntity) {
fDTDHandler.endParameterEntity(name, null);
} }
// end DTD // end DTD
......
/* /*
* 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 * Licensed to the Apache Software Foundation (ASF) under one or more
...@@ -67,7 +67,7 @@ import com.sun.xml.internal.stream.Entity; ...@@ -67,7 +67,7 @@ import com.sun.xml.internal.stream.Entity;
* @author Eric Ye, IBM * @author Eric Ye, IBM
* @author K.Venugopal SUN Microsystems * @author K.Venugopal SUN Microsystems
* @author Sunitha Reddy, SUN Microsystems * @author Sunitha Reddy, SUN Microsystems
* @LastModified: Nov 2017 * @LastModified: Feb 2020
*/ */
public abstract class XMLScanner public abstract class XMLScanner
implements XMLComponent { implements XMLComponent {
...@@ -1239,10 +1239,10 @@ public abstract class XMLScanner ...@@ -1239,10 +1239,10 @@ public abstract class XMLScanner
* @throws XNIException Thrown by handler to signal an error. * @throws XNIException Thrown by handler to signal an error.
*/ */
public void endEntity(String name, Augmentations augs) throws IOException, XNIException { public void endEntity(String name, Augmentations augs) throws IOException, XNIException {
// keep track of the entity depth // keep track of the entity depth
fEntityDepth--; if (fEntityDepth > 0) {
fEntityDepth--;
}
} // endEntity(String) } // endEntity(String)
/** /**
......
/* /*
* 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 * Licensed to the Apache Software Foundation (ASF) under one or more
...@@ -62,7 +62,7 @@ import java.util.Random; ...@@ -62,7 +62,7 @@ import java.util.Random;
* @author Andy Clark, IBM * @author Andy Clark, IBM
* @author Neil Graham, IBM * @author Neil Graham, IBM
* *
* @LastModified: Oct 2017 * @LastModified: Feb 2020
*/ */
public class DTDGrammar public class DTDGrammar
implements XMLDTDHandler, XMLDTDContentModelHandler, EntityState, Grammar { implements XMLDTDHandler, XMLDTDContentModelHandler, EntityState, Grammar {
...@@ -447,9 +447,12 @@ public class DTDGrammar ...@@ -447,9 +447,12 @@ public class DTDGrammar
* @throws XNIException Thrown by handler to signal an error. * @throws XNIException Thrown by handler to signal an error.
*/ */
public void endParameterEntity(String name, Augmentations augs) throws XNIException { public void endParameterEntity(String name, Augmentations augs) throws XNIException {
// redundant check as this method can only be called after parsing a PE
fPEDepth--; // incomplete or truncated DTD get caught before reaching this method
fReadingExternalDTD = fPEntityStack[fPEDepth]; if (fPEDepth > 0) {
fPEDepth--;
fReadingExternalDTD = fPEntityStack[fPEDepth];
}
} // endParameterEntity(String,Augmentations) } // endParameterEntity(String,Augmentations)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册