mirror of
https://github.com/tristanpenman/valijson.git
synced 2025-01-24 02:51:34 +01:00
Detect certain JSON reference cycles while parsing schemas
This commit is contained in:
parent
ae0112b4be
commit
b151d1e99a
12
include/valijson/schema_cache.hpp
Normal file
12
include/valijson/schema_cache.hpp
Normal file
@ -0,0 +1,12 @@
|
||||
#pragma once
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
#include <valijson/subschema.hpp>
|
||||
|
||||
namespace valijson {
|
||||
|
||||
typedef std::map<std::string, const Subschema *> SchemaCache;
|
||||
|
||||
} // namespace valijson
|
@ -1,10 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdexcept>
|
||||
#include <functional>
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
#include <functional>
|
||||
|
||||
#include <valijson/constraints/concrete_constraints.hpp>
|
||||
#include <valijson/internal/adapter.hpp>
|
||||
@ -14,6 +12,7 @@
|
||||
#include <valijson/internal/uri.hpp>
|
||||
#include <valijson/constraint_builder.hpp>
|
||||
#include <valijson/schema.hpp>
|
||||
#include <valijson/schema_cache.hpp>
|
||||
#include <valijson/exceptions.hpp>
|
||||
|
||||
namespace valijson {
|
||||
@ -109,8 +108,8 @@ public:
|
||||
void populateSchema(
|
||||
const AdapterType &node,
|
||||
Schema &schema,
|
||||
typename FunctionPtrs<AdapterType>::FetchDoc fetchDoc = nullptr ,
|
||||
typename FunctionPtrs<AdapterType>::FreeDoc freeDoc = nullptr )
|
||||
typename FunctionPtrs<AdapterType>::FetchDoc fetchDoc = nullptr,
|
||||
typename FunctionPtrs<AdapterType>::FreeDoc freeDoc = nullptr)
|
||||
{
|
||||
if ((fetchDoc == nullptr ) ^ (freeDoc == nullptr)) {
|
||||
throwRuntimeError("Remote document fetching can't be enabled without both fetch and free functions");
|
||||
@ -148,8 +147,6 @@ private:
|
||||
typedef std::map<std::string, const DocumentType*> Type;
|
||||
};
|
||||
|
||||
typedef std::map<std::string, const Subschema *> SchemaCache;
|
||||
|
||||
/**
|
||||
* @brief Free memory used by fetched documents
|
||||
*
|
||||
@ -478,6 +475,10 @@ private:
|
||||
|
||||
}
|
||||
|
||||
if (std::find(newCacheKeys.begin(), newCacheKeys.end(), queryKey) != newCacheKeys.end()) {
|
||||
throwRuntimeError("found cycle while resolving JSON reference");
|
||||
}
|
||||
|
||||
// JSON References in nested schema will be resolved relative to the
|
||||
// current document
|
||||
const AdapterType &referencedAdapter =
|
||||
|
Loading…
x
Reference in New Issue
Block a user