| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "components/json_schema/json_schema_validator.h" | 5 #include "components/json_schema/json_schema_validator.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <cfloat> | 8 #include <cfloat> |
| 9 #include <cmath> | 9 #include <cmath> |
| 10 | 10 |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 const ExpectedType* end = kExpectedTypes + arraysize(kExpectedTypes); | 155 const ExpectedType* end = kExpectedTypes + arraysize(kExpectedTypes); |
| 156 const ExpectedType* entry = std::lower_bound( | 156 const ExpectedType* entry = std::lower_bound( |
| 157 kExpectedTypes, end, it.key(), CompareToString); | 157 kExpectedTypes, end, it.key(), CompareToString); |
| 158 if (entry == end || entry->key != it.key()) { | 158 if (entry == end || entry->key != it.key()) { |
| 159 if (options & JSONSchemaValidator::OPTIONS_IGNORE_UNKNOWN_ATTRIBUTES) | 159 if (options & JSONSchemaValidator::OPTIONS_IGNORE_UNKNOWN_ATTRIBUTES) |
| 160 continue; | 160 continue; |
| 161 *error = base::StringPrintf("Invalid attribute %s", it.key().c_str()); | 161 *error = base::StringPrintf("Invalid attribute %s", it.key().c_str()); |
| 162 return false; | 162 return false; |
| 163 } | 163 } |
| 164 | 164 |
| 165 if (!it.value().IsType(entry->type)) { | 165 // Integer can be converted to double. |
| 166 if (!(it.value().IsType(entry->type) || |
| 167 (it.value().IsType(base::Value::TYPE_INTEGER) && |
| 168 entry->type == base::Value::TYPE_DOUBLE))) { |
| 166 *error = base::StringPrintf("Invalid value for %s attribute", | 169 *error = base::StringPrintf("Invalid value for %s attribute", |
| 167 it.key().c_str()); | 170 it.key().c_str()); |
| 168 return false; | 171 return false; |
| 169 } | 172 } |
| 170 | 173 |
| 171 // base::Value::TYPE_INTEGER attributes must be >= 0. | 174 // base::Value::TYPE_INTEGER attributes must be >= 0. |
| 172 // This applies to "minItems", "maxItems", "minLength" and "maxLength". | 175 // This applies to "minItems", "maxItems", "minLength" and "maxLength". |
| 173 if (it.value().IsType(base::Value::TYPE_INTEGER)) { | 176 if (it.value().IsType(base::Value::TYPE_INTEGER)) { |
| 174 int integer_value; | 177 int integer_value; |
| 175 it.value().GetAsInteger(&integer_value); | 178 it.value().GetAsInteger(&integer_value); |
| (...skipping 582 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 758 | 761 |
| 759 if (*additional_properties_schema) { | 762 if (*additional_properties_schema) { |
| 760 std::string additional_properties_type(schema::kAny); | 763 std::string additional_properties_type(schema::kAny); |
| 761 CHECK((*additional_properties_schema)->GetString( | 764 CHECK((*additional_properties_schema)->GetString( |
| 762 schema::kType, &additional_properties_type)); | 765 schema::kType, &additional_properties_type)); |
| 763 return additional_properties_type == schema::kAny; | 766 return additional_properties_type == schema::kAny; |
| 764 } else { | 767 } else { |
| 765 return default_allow_additional_properties_; | 768 return default_allow_additional_properties_; |
| 766 } | 769 } |
| 767 } | 770 } |
| OLD | NEW |