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

Side by Side Diff: components/policy/core/common/schema.cc

Issue 94043003: Ignore unknown attributes when parsing JSON schemas. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: added Options enum Created 7 years 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 | Annotate | Revision Log
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/policy/core/common/schema.h" 5 #include "components/policy/core/common/schema.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <map> 8 #include <map>
9 #include <utility> 9 #include <utility>
10 #include <vector> 10 #include <vector>
(...skipping 482 matching lines...) Expand 10 before | Expand all | Expand 10 after
493 if (!*it || !GetItems().Validate(**it)) 493 if (!*it || !GetItems().Validate(**it))
494 return false; 494 return false;
495 } 495 }
496 } 496 }
497 497
498 return true; 498 return true;
499 } 499 }
500 500
501 // static 501 // static
502 Schema Schema::Parse(const std::string& content, std::string* error) { 502 Schema Schema::Parse(const std::string& content, std::string* error) {
503 // Validate as a generic JSON schema. 503 // Validate as a generic JSON schema, and ignore unknown attributes; they
504 scoped_ptr<base::DictionaryValue> dict = 504 // may become used in a future version of the schema format.
505 JSONSchemaValidator::IsValidSchema(content, error); 505 scoped_ptr<base::DictionaryValue> dict = JSONSchemaValidator::IsValidSchema(
506 content, JSONSchemaValidator::OPTIONS_IGNORE_UNKNOWN_ATTRIBUTES, error);
506 if (!dict) 507 if (!dict)
507 return Schema(); 508 return Schema();
508 509
509 // Validate the main type. 510 // Validate the main type.
510 std::string string_value; 511 std::string string_value;
511 if (!dict->GetString(schema::kType, &string_value) || 512 if (!dict->GetString(schema::kType, &string_value) ||
512 string_value != schema::kObject) { 513 string_value != schema::kObject) {
513 *error = 514 *error =
514 "The main schema must have a type attribute with \"object\" value."; 515 "The main schema must have a type attribute with \"object\" value.";
515 return Schema(); 516 return Schema();
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
577 578
578 Schema Schema::GetItems() const { 579 Schema Schema::GetItems() const {
579 CHECK(valid()); 580 CHECK(valid());
580 CHECK_EQ(base::Value::TYPE_LIST, type()); 581 CHECK_EQ(base::Value::TYPE_LIST, type());
581 if (node_->extra == kInvalid) 582 if (node_->extra == kInvalid)
582 return Schema(); 583 return Schema();
583 return Schema(storage_, storage_->schema(node_->extra)); 584 return Schema(storage_, storage_->schema(node_->extra));
584 } 585 }
585 586
586 } // namespace policy 587 } // namespace policy
OLDNEW
« no previous file with comments | « components/json_schema/json_schema_validator_unittest.cc ('k') | components/policy/core/common/schema_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698