diff options
-rw-r--r-- | include/rapidjson/schema.h | 13 | ||||
-rw-r--r-- | test/unittest/schematest.cpp | 2 |
2 files changed, 11 insertions, 4 deletions
diff --git a/include/rapidjson/schema.h b/include/rapidjson/schema.h index 0a8bb7c5..36846186 100644 --- a/include/rapidjson/schema.h +++ b/include/rapidjson/schema.h @@ -32,11 +32,13 @@ RAPIDJSON_DIAG_OFF(c++98-compat-pedantic) #define RAPIDJSON_SCHEMA_USE_INTERNALREGEX 0 #endif -#if !RAPIDJSON_SCHEMA_USE_INTERNALREGEX && !defined(RAPIDJSON_SCHEMA_USE_STDREGEX) && (__cplusplus >=201103L || (defined(_MSC_VER) && _MSC_VER >= 1800)) +#if !defined(RAPIDJSON_SCHEMA_USE_STDREGEX) +#if !RAPIDJSON_SCHEMA_USE_INTERNALREGEX && (__cplusplus >=201103L || (defined(_MSC_VER) && _MSC_VER >= 1800)) #define RAPIDJSON_SCHEMA_USE_STDREGEX 1 #else #define RAPIDJSON_SCHEMA_USE_STDREGEX 0 #endif +#endif #if RAPIDJSON_SCHEMA_USE_INTERNALREGEX #include "internal/regex.h" @@ -1017,12 +1019,17 @@ private: #elif RAPIDJSON_SCHEMA_USE_STDREGEX template <typename ValueType> RegexType* CreatePattern(const ValueType& value) { - if (value.IsString()) + if (value.IsString()) { + RegexType* r = static_cast<RegexType*>(allocator_->Malloc(sizeof(RegexType))); try { - return new (allocator_->Malloc(sizeof(RegexType))) RegexType(value.GetString(), std::size_t(value.GetStringLength()), std::regex_constants::ECMAScript); + new (r) RegexType(value.GetString(), std::size_t(value.GetStringLength()), std::regex_constants::ECMAScript); } catch (const std::regex_error&) { + AllocatorType::Free(r); + r = 0; } + return r; + } return 0; } diff --git a/test/unittest/schematest.cpp b/test/unittest/schematest.cpp index d1027ad5..e65a3857 100644 --- a/test/unittest/schematest.cpp +++ b/test/unittest/schematest.cpp @@ -352,7 +352,7 @@ TEST(SchemaValidator, String_Pattern) { TEST(SchemaValidator, String_Pattern_Invalid) { Document sd; - sd.Parse("{\"type\":\"string\",\"pattern\":\"a{0}\"}"); // TODO: report regex is invalid somehow + sd.Parse("{\"type\":\"string\",\"pattern\":\"a{}\"}"); // TODO: report regex is invalid somehow SchemaDocument s(sd); VALIDATE(s, "\"\"", true); |