Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(63)

Side by Side Diff: components/json_schema/json_schema_validator.cc

Issue 138003003: Add additional restriction to policy schema internal (part1) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: more fixes Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | components/policy/core/common/schema.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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 }
OLDNEW
« no previous file with comments | « no previous file | components/policy/core/common/schema.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698