Keep Document value unchanged on parse error, fixes #437
Keeping the DOM unchanged in case of an error is the intended behaviour according to the [documentation] [1]. Instead of forcing the value to `kNullType` before starting the parsing, store the parsed value upon success via regular move. [1]: https://miloyip.github.io/rapidjson/md_doc_dom.html#ParseError
This commit is contained in:
parent
221887d682
commit
fa123699d3
@ -1886,14 +1886,13 @@ public:
|
|||||||
*/
|
*/
|
||||||
template <unsigned parseFlags, typename SourceEncoding, typename InputStream>
|
template <unsigned parseFlags, typename SourceEncoding, typename InputStream>
|
||||||
GenericDocument& ParseStream(InputStream& is) {
|
GenericDocument& ParseStream(InputStream& is) {
|
||||||
ValueType::SetNull(); // Remove existing root if exist
|
|
||||||
GenericReader<SourceEncoding, Encoding, StackAllocator> reader(
|
GenericReader<SourceEncoding, Encoding, StackAllocator> reader(
|
||||||
stack_.HasAllocator() ? &stack_.GetAllocator() : 0);
|
stack_.HasAllocator() ? &stack_.GetAllocator() : 0);
|
||||||
ClearStackOnExit scope(*this);
|
ClearStackOnExit scope(*this);
|
||||||
parseResult_ = reader.template Parse<parseFlags>(is, *this);
|
parseResult_ = reader.template Parse<parseFlags>(is, *this);
|
||||||
if (parseResult_) {
|
if (parseResult_) {
|
||||||
RAPIDJSON_ASSERT(stack_.GetSize() == sizeof(ValueType)); // Got one and only one root object
|
RAPIDJSON_ASSERT(stack_.GetSize() == sizeof(ValueType)); // Got one and only one root object
|
||||||
this->RawAssign(*stack_.template Pop<ValueType>(1)); // Add this-> to prevent issue 13.
|
ValueType::operator=(*stack_.template Pop<ValueType>(1));// Move value from stack to document
|
||||||
}
|
}
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user