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 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
188 return false; | 188 return false; |
189 } | 189 } |
190 } | 190 } |
191 | 191 |
192 // Validate the values contained in an "enum" attribute. | 192 // Validate the values contained in an "enum" attribute. |
193 if (it.key() == schema::kEnum) { | 193 if (it.key() == schema::kEnum) { |
194 it.value().GetAsList(&list_value); | 194 it.value().GetAsList(&list_value); |
195 for (size_t i = 0; i < list_value->GetSize(); ++i) { | 195 for (size_t i = 0; i < list_value->GetSize(); ++i) { |
196 const base::Value* value = NULL; | 196 const base::Value* value = NULL; |
197 list_value->Get(i, &value); | 197 list_value->Get(i, &value); |
198 const base::DictionaryValue* value_dict; | |
not at google - send to devlin
2013/10/28 18:00:25
= NULL
Sam McNally
2013/10/29 00:39:02
Done.
| |
199 if (value->GetAsDictionary(&value_dict)) { | |
200 if (!value_dict->Get("name", &value)) { | |
201 *error = "Invalid value in enum attribute"; | |
202 return false; | |
203 } | |
204 } | |
198 switch (value->GetType()) { | 205 switch (value->GetType()) { |
199 case base::Value::TYPE_NULL: | 206 case base::Value::TYPE_NULL: |
200 case base::Value::TYPE_BOOLEAN: | 207 case base::Value::TYPE_BOOLEAN: |
201 case base::Value::TYPE_INTEGER: | 208 case base::Value::TYPE_INTEGER: |
202 case base::Value::TYPE_DOUBLE: | 209 case base::Value::TYPE_DOUBLE: |
203 case base::Value::TYPE_STRING: | 210 case base::Value::TYPE_STRING: |
204 break; | 211 break; |
205 default: | 212 default: |
206 *error = "Invalid value in enum attribute"; | 213 *error = "Invalid value in enum attribute"; |
207 return false; | 214 return false; |
not at google - send to devlin
2013/10/28 18:00:25
rather than the GetAsDictionary above, include TYP
Sam McNally
2013/10/29 00:39:02
I think I need to keep it before the switch so the
not at google - send to devlin
2013/10/29 16:25:16
Ah right. Could you add a comment ("sometimes the
Sam McNally
2013/10/30 03:08:37
Done.
| |
208 } | 215 } |
209 } | 216 } |
210 } | 217 } |
211 | 218 |
212 // Validate the schemas contained in a "choices" attribute. | 219 // Validate the schemas contained in a "choices" attribute. |
213 if (it.key() == schema::kChoices) { | 220 if (it.key() == schema::kChoices) { |
214 it.value().GetAsList(&list_value); | 221 it.value().GetAsList(&list_value); |
215 for (size_t i = 0; i < list_value->GetSize(); ++i) { | 222 for (size_t i = 0; i < list_value->GetSize(); ++i) { |
216 if (!list_value->GetDictionary(i, &dictionary_value)) { | 223 if (!list_value->GetDictionary(i, &dictionary_value)) { |
217 *error = "Invalid choices attribute"; | 224 *error = "Invalid choices attribute"; |
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
472 errors_.push_back(Error(path, kInvalidChoice)); | 479 errors_.push_back(Error(path, kInvalidChoice)); |
473 return; | 480 return; |
474 } | 481 } |
475 | 482 |
476 void JSONSchemaValidator::ValidateEnum(const base::Value* instance, | 483 void JSONSchemaValidator::ValidateEnum(const base::Value* instance, |
477 const base::ListValue* choices, | 484 const base::ListValue* choices, |
478 const std::string& path) { | 485 const std::string& path) { |
479 for (size_t i = 0; i < choices->GetSize(); ++i) { | 486 for (size_t i = 0; i < choices->GetSize(); ++i) { |
480 const base::Value* choice = NULL; | 487 const base::Value* choice = NULL; |
481 CHECK(choices->Get(i, &choice)); | 488 CHECK(choices->Get(i, &choice)); |
489 const base::DictionaryValue* choice_dict; | |
490 if (choice->GetAsDictionary(&choice_dict)) { | |
491 if (!choice_dict->Get("name", &choice)) { | |
492 NOTREACHED(); | |
493 } | |
494 } | |
not at google - send to devlin
2013/10/28 18:00:25
likewise
not at google - send to devlin
2013/10/29 16:25:16
(still applicable)
Sam McNally
2013/10/30 03:08:37
Done (before the switch for the same reason).
| |
482 switch (choice->GetType()) { | 495 switch (choice->GetType()) { |
483 case base::Value::TYPE_NULL: | 496 case base::Value::TYPE_NULL: |
484 case base::Value::TYPE_BOOLEAN: | 497 case base::Value::TYPE_BOOLEAN: |
485 case base::Value::TYPE_STRING: | 498 case base::Value::TYPE_STRING: |
486 if (instance->Equals(choice)) | 499 if (instance->Equals(choice)) |
487 return; | 500 return; |
488 break; | 501 break; |
489 | 502 |
490 case base::Value::TYPE_INTEGER: | 503 case base::Value::TYPE_INTEGER: |
491 case base::Value::TYPE_DOUBLE: | 504 case base::Value::TYPE_DOUBLE: |
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
718 | 731 |
719 if (*additional_properties_schema) { | 732 if (*additional_properties_schema) { |
720 std::string additional_properties_type(schema::kAny); | 733 std::string additional_properties_type(schema::kAny); |
721 CHECK((*additional_properties_schema)->GetString( | 734 CHECK((*additional_properties_schema)->GetString( |
722 schema::kType, &additional_properties_type)); | 735 schema::kType, &additional_properties_type)); |
723 return additional_properties_type == schema::kAny; | 736 return additional_properties_type == schema::kAny; |
724 } else { | 737 } else { |
725 return default_allow_additional_properties_; | 738 return default_allow_additional_properties_; |
726 } | 739 } |
727 } | 740 } |
OLD | NEW |