IDEA-231779 JSON Schema Validator: Integer values restricted to 32 bit during validation

GitOrigin-RevId: 3b771fda1d32e47b179b0c92258fe3f35f586750
This commit is contained in:
Anton Lobov
2020-01-30 18:31:30 +00:00
committed by intellij-monorepo-bot
parent e84885999b
commit e1d5c85239
2 changed files with 31 additions and 64 deletions
@@ -758,46 +758,23 @@ class JsonSchemaAnnotatorChecker {
Number exclusiveMaximumNumber = schema.getExclusiveMaximumNumber();
if (exclusiveMaximumNumber != null) {
if (JsonSchemaType._integer.equals(propValueType)) {
final int intValue = exclusiveMaximumNumber.intValue();
if (value.intValue() >= intValue) {
error("Greater than an exclusive maximum " + intValue, propertyValue, JsonErrorPriority.LOW_PRIORITY);
}
}
else {
final double doubleValue = exclusiveMaximumNumber.doubleValue();
if (value.doubleValue() >= doubleValue) {
error("Greater than an exclusive maximum " + exclusiveMaximumNumber, propertyValue, JsonErrorPriority.LOW_PRIORITY);
}
final double doubleValue = exclusiveMaximumNumber.doubleValue();
if (value.doubleValue() >= doubleValue) {
error("Greater than an exclusive maximum " + exclusiveMaximumNumber, propertyValue, JsonErrorPriority.LOW_PRIORITY);
}
}
Number maximum = schema.getMaximum();
if (maximum == null) return;
boolean isExclusive = Boolean.TRUE.equals(schema.isExclusiveMaximum());
if (JsonSchemaType._integer.equals(propValueType)) {
final int intValue = maximum.intValue();
if (isExclusive) {
if (value.intValue() >= intValue) {
error("Greater than an exclusive maximum " + intValue, propertyValue, JsonErrorPriority.LOW_PRIORITY);
}
}
else {
if (value.intValue() > intValue) {
error("Greater than a maximum " + intValue, propertyValue, JsonErrorPriority.LOW_PRIORITY);
}
final double doubleValue = maximum.doubleValue();
if (isExclusive) {
if (value.doubleValue() >= doubleValue) {
error("Greater than an exclusive maximum " + maximum, propertyValue, JsonErrorPriority.LOW_PRIORITY);
}
}
else {
final double doubleValue = maximum.doubleValue();
if (isExclusive) {
if (value.doubleValue() >= doubleValue) {
error("Greater than an exclusive maximum " + maximum, propertyValue, JsonErrorPriority.LOW_PRIORITY);
}
}
else {
if (value.doubleValue() > doubleValue) {
error("Greater than a maximum " + maximum, propertyValue, JsonErrorPriority.LOW_PRIORITY);
}
if (value.doubleValue() > doubleValue) {
error("Greater than a maximum " + maximum, propertyValue, JsonErrorPriority.LOW_PRIORITY);
}
}
}
@@ -807,47 +784,24 @@ class JsonSchemaAnnotatorChecker {
// schema v6 - exclusiveMinimum is numeric now
Number exclusiveMinimumNumber = schema.getExclusiveMinimumNumber();
if (exclusiveMinimumNumber != null) {
if (JsonSchemaType._integer.equals(schemaType)) {
final int intValue = exclusiveMinimumNumber.intValue();
if (value.intValue() <= intValue) {
error("Less than an exclusive minimum" + intValue, propertyValue, JsonErrorPriority.LOW_PRIORITY);
}
}
else {
final double doubleValue = exclusiveMinimumNumber.doubleValue();
if (value.doubleValue() <= doubleValue) {
error("Less than an exclusive minimum " + exclusiveMinimumNumber, propertyValue, JsonErrorPriority.LOW_PRIORITY);
}
final double doubleValue = exclusiveMinimumNumber.doubleValue();
if (value.doubleValue() <= doubleValue) {
error("Less than an exclusive minimum " + exclusiveMinimumNumber, propertyValue, JsonErrorPriority.LOW_PRIORITY);
}
}
Number minimum = schema.getMinimum();
if (minimum == null) return;
boolean isExclusive = Boolean.TRUE.equals(schema.isExclusiveMinimum());
if (JsonSchemaType._integer.equals(schemaType)) {
final int intValue = minimum.intValue();
if (isExclusive) {
if (value.intValue() <= intValue) {
error("Less than an exclusive minimum " + intValue, propertyValue, JsonErrorPriority.LOW_PRIORITY);
}
}
else {
if (value.intValue() < intValue) {
error("Less than a minimum " + intValue, propertyValue, JsonErrorPriority.LOW_PRIORITY);
}
final double doubleValue = minimum.doubleValue();
if (isExclusive) {
if (value.doubleValue() <= doubleValue) {
error("Less than an exclusive minimum " + minimum, propertyValue, JsonErrorPriority.LOW_PRIORITY);
}
}
else {
final double doubleValue = minimum.doubleValue();
if (isExclusive) {
if (value.doubleValue() <= doubleValue) {
error("Less than an exclusive minimum " + minimum, propertyValue, JsonErrorPriority.LOW_PRIORITY);
}
}
else {
if (value.doubleValue() < doubleValue) {
error("Less than a minimum " + minimum, propertyValue, JsonErrorPriority.LOW_PRIORITY);
}
if (value.doubleValue() < doubleValue) {
error("Less than a minimum " + minimum, propertyValue, JsonErrorPriority.LOW_PRIORITY);
}
}
}
@@ -1184,4 +1184,17 @@ public class JsonSchemaHighlightingTest extends JsonSchemaHighlightingTestBase {
@Language("JSON") String schemaText = FileUtil.loadFile(new File(getTestDataPath() + "/functionSchema.json"));
doTest(schemaText, "{\"bindings\": [\"queueTrigger\"]}");
}
public void testLargeInteger() {
doTest("{\n" +
" \"properties\": {\n" +
" \"sampled\": {\n" +
" \"type\": \"integer\",\n" +
" \"minimum\": 0\n" +
" }\n" +
" }\n" +
"}", "{\n" +
" \"sampled\": 15123456789 \n" +
"}\n");
}
}