#526 Incorporating review comments

* renaming accessors
* changing the default to disallow external resources
* introduced system-property for backwards compatibility
* honor system-property (if present) and SVGReadParams.isAllowExternalResources hasn't been called
  (as against ignoring system-property and reverting to 'block-by-default' if SVGReadParams.isAllowExternalResources invoked)
* added + updated test cases
This commit is contained in:
Ashish Chopra
2020-03-24 18:40:01 +05:30
parent 7bf99fb496
commit 872523b0f0
3 changed files with 97 additions and 49 deletions
@@ -79,8 +79,12 @@ import java.util.Map;
* @see <A href="http://www.mail-archive.com/batik-dev@xml.apache.org/msg00992.html">batik-dev</A>
*/
public class SVGImageReader extends ImageReaderBase {
static String ALLOW_EXTERNAL_RESOURCES_SYSTEM_PROP = "com.twelvemonkeys.imageio.plugins.svg.allowexternalresources";
private Rasterizer rasterizer;
private boolean allowExternalResources;
private boolean allowExternalResources =
"true".equalsIgnoreCase(System.getProperty(ALLOW_EXTERNAL_RESOURCES_SYSTEM_PROP));
/**
* Creates an {@code SVGImageReader}.
@@ -89,7 +93,6 @@ public class SVGImageReader extends ImageReaderBase {
*/
public SVGImageReader(final ImageReaderSpi pProvider) {
super(pProvider);
allowExternalResources = true;
}
protected void resetMembers() {
@@ -119,7 +122,7 @@ public class SVGImageReader extends ImageReaderBase {
SVGReadParam svgParam = (SVGReadParam) pParam;
// set the external-resource-resolution preference
allowExternalResources = svgParam.shouldAllowExternalResources();
allowExternalResources = svgParam.isAllowExternalResources();
// Get the base URI
// This must be done before converting the params to hints
@@ -41,11 +41,11 @@ import java.awt.*;
public class SVGReadParam extends ImageReadParam {
private Paint background;
private String baseURI;
private boolean allowExternalResources;
private boolean allowExternalResources = false;
private boolean isAllowExternalResourcesSetExplicitly = false;
public SVGReadParam() {
super();
allowExternalResources = true;
}
public Paint getBackgroundColor() {
@@ -64,12 +64,18 @@ public class SVGReadParam extends ImageReadParam {
baseURI = pBaseURI;
}
public void allowExternalResources(boolean bAllow) {
allowExternalResources = bAllow;
public void setAllowExternalResources(boolean allow) {
allowExternalResources = allow;
isAllowExternalResourcesSetExplicitly = true;
}
public boolean shouldAllowExternalResources() {
return allowExternalResources;
public boolean isAllowExternalResources() {
if (isAllowExternalResourcesSetExplicitly) {
return allowExternalResources;
} else {
// prefer the explicitly set value if invoked, read the system prop as a fallback if it wasn't
return "true".equals(System.getProperty(SVGImageReader.ALLOW_EXTERNAL_RESOURCES_SYSTEM_PROP));
}
}
@Override