Fix: Add null check in JsonParser, Relax property handling introduced in Jaxp 1.5 for some compatibility with existing 1.4 version
This commit is contained in:
parent
804b271764
commit
284f0f14b0
|
@ -9,9 +9,9 @@ package ca.uhn.fhir.parser;
|
|||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
|
@ -133,7 +133,7 @@ public class JsonParser extends BaseParser implements IParser {
|
|||
/**
|
||||
* Do not use this constructor, the recommended way to obtain a new instance of the JSON parser is to invoke
|
||||
* {@link FhirContext#newJsonParser()}.
|
||||
*
|
||||
*
|
||||
* @param theParserErrorHandler
|
||||
*/
|
||||
public JsonParser(FhirContext theContext, IParserErrorHandler theParserErrorHandler) {
|
||||
|
@ -1026,7 +1026,7 @@ public class JsonParser extends BaseParser implements IParser {
|
|||
|
||||
private JsonArray grabJsonArray(JsonObject theObject, String nextName, String thePosition) {
|
||||
JsonValue object = theObject.get(nextName);
|
||||
if (object == null) {
|
||||
if (object == null || object.getValueType()==ValueType.NULL) {
|
||||
return null;
|
||||
}
|
||||
if (object.getValueType() != ValueType.ARRAY) {
|
||||
|
|
|
@ -9,9 +9,9 @@ package ca.uhn.fhir.validation;
|
|||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
|
@ -44,6 +44,7 @@ import org.hl7.fhir.instance.model.api.IBaseResource;
|
|||
import org.w3c.dom.ls.LSInput;
|
||||
import org.w3c.dom.ls.LSResourceResolver;
|
||||
import org.xml.sax.SAXException;
|
||||
import org.xml.sax.SAXNotRecognizedException;
|
||||
import org.xml.sax.SAXParseException;
|
||||
|
||||
import ca.uhn.fhir.context.ConfigurationException;
|
||||
|
@ -93,12 +94,16 @@ public class SchemaBaseValidator implements IValidatorModule {
|
|||
encodedResource = theContext.getFhirContext().newXmlParser().encodeResourceToString((IBaseResource) theContext.getResource());
|
||||
}
|
||||
|
||||
try {
|
||||
/*
|
||||
* See https://github.com/jamesagnew/hapi-fhir/issues/339
|
||||
* https://www.owasp.org/index.php/XML_External_Entity_(XXE)_Processing
|
||||
*/
|
||||
validator.setProperty(XMLConstants.ACCESS_EXTERNAL_DTD, "");
|
||||
validator.setProperty(XMLConstants.ACCESS_EXTERNAL_SCHEMA, "");
|
||||
validator.setProperty(XMLConstants.ACCESS_EXTERNAL_DTD, "");
|
||||
validator.setProperty(XMLConstants.ACCESS_EXTERNAL_SCHEMA, "");
|
||||
}catch (SAXNotRecognizedException ex){
|
||||
ourLog.warn("Jaxp 1.5 Support not found.",ex);
|
||||
}
|
||||
|
||||
validator.validate(new StreamSource(new StringReader(encodedResource)));
|
||||
} catch (SAXParseException e) {
|
||||
|
@ -132,13 +137,15 @@ public class SchemaBaseValidator implements IValidatorModule {
|
|||
schemaFactory.setResourceResolver(new MyResourceResolver());
|
||||
|
||||
try {
|
||||
|
||||
try {
|
||||
/*
|
||||
* See https://github.com/jamesagnew/hapi-fhir/issues/339
|
||||
* https://www.owasp.org/index.php/XML_External_Entity_(XXE)_Processing
|
||||
*/
|
||||
schemaFactory.setProperty(XMLConstants.ACCESS_EXTERNAL_DTD, "");
|
||||
|
||||
schemaFactory.setProperty(XMLConstants.ACCESS_EXTERNAL_DTD, "");
|
||||
}catch (SAXNotRecognizedException snex){
|
||||
ourLog.warn("Jaxp 1.5 Support not found.",snex);
|
||||
}
|
||||
schema = schemaFactory.newSchema(new Source[] { baseSource });
|
||||
} catch (SAXException e) {
|
||||
throw new ConfigurationException("Could not load/parse schema file: " + theSchemaName, e);
|
||||
|
|
Loading…
Reference in New Issue