Fix #366 - Return HTTP 400 instead of 500 when boolean values contain invalid string

This commit is contained in:
jamesagnew 2016-05-21 13:07:46 -04:00
parent 3d8776f6ed
commit 021025ffa9
4 changed files with 35 additions and 1 deletions

View File

@ -2263,6 +2263,20 @@ public class XmlParserDstu2Test {
ourCtx.newJsonParser().parseResource(encoded);
}
/**
* See #366
*/
@Test(expected=DataFormatException.class)
public void testParseInvalidBoolean() {
//@formatter:off
String resource = "<Patient xmlns=\"http://hl7.org/fhir\">\n" +
" <active value=\"1\"/>\n" +
"</Patient>";
//@formatter:on
ourCtx.newXmlParser().parseResource(resource);
}
/**
* See #216
*/

View File

@ -34,6 +34,7 @@ package org.hl7.fhir.dstu3.model;
import org.hl7.fhir.instance.model.api.IBaseBooleanDatatype;
import ca.uhn.fhir.model.api.annotation.DatatypeDef;
import ca.uhn.fhir.parser.DataFormatException;
/**
* Primitive type "boolean" in FHIR "true" or "false"
@ -96,7 +97,7 @@ public class BooleanType extends PrimitiveType<Boolean> implements IBaseBooleanD
} else if ("false".equals(value)) {
return Boolean.FALSE;
} else {
throw new IllegalArgumentException("Invalid boolean string: '" + theValue + "'");
throw new DataFormatException("Invalid boolean string: '" + theValue + "'");
}
}
}

View File

@ -2431,6 +2431,20 @@ public class XmlParserDstu3Test {
public void testParseInvalid() {
ourCtx.newXmlParser().parseResource("FOO");
}
/**
* See #366
*/
@Test(expected=DataFormatException.class)
public void testParseInvalidBoolean() {
//@formatter:off
String resource = "<Patient xmlns=\"http://hl7.org/fhir\">\n" +
" <active value=\"1\"/>\n" +
"</Patient>";
//@formatter:on
ourCtx.newXmlParser().parseResource(resource);
}
@Test
public void testParseInvalidTextualNumber() {

View File

@ -203,6 +203,11 @@
<![CDATA[<a href="./doc_jpa.html">JPA Documentation</a>]]> for information on
how to use this. Thanks to Naminder Soorma for the suggestion!
</action>
<action type="fix" issue="366">
When posting a resource to a server that contains an invalid value in a boolean field
(e.g. Patient with an active value of "1") the server should return an HTTP 400, not
an HTTP 500. Thanks to Jim Steel for reporting!
</action>
</release>
<release version="1.5" date="2016-04-20">
<action type="fix" issue="339">