diff --git a/include/json/value.h b/include/json/value.h index fe2f9eb..19e2966 100644 --- a/include/json/value.h +++ b/include/json/value.h @@ -317,8 +317,10 @@ namespace Json { // EnumValues enumValues() const; //# endif + /// Comments must be //... or /* ... */ void setComment( const char *comment, CommentPlacement placement ); + /// Comments must be //... or /* ... */ void setComment( const std::string &comment, CommentPlacement placement ); bool hasComment( CommentPlacement placement ) const; diff --git a/src/lib_json/json_value.cpp b/src/lib_json/json_value.cpp index b3e90b6..0fb735f 100644 --- a/src/lib_json/json_value.cpp +++ b/src/lib_json/json_value.cpp @@ -1,3 +1,4 @@ +#include #include #include #include @@ -149,6 +150,9 @@ Value::CommentInfo::setComment( const char *text ) { if ( comment_ ) valueAllocator()->releaseStringValue( comment_ ); + JSON_ASSERT( text ); + JSON_ASSERT_MESSAGE( text[0]==NULL || text[0]=='/', "Comments must start with /"); + // It seems that /**/ style comments are acceptable as well. comment_ = valueAllocator()->duplicateStringValue( text ); }