xmldocument::save: use encoding interpreted by get_write_encoding in buffered_writer constructor #621
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is a preemptive patch, for something that is currently not a bug, but could become one in the future.
xml_document::save
currently constructsbuffered_writer
with parameterencoding
:https://github.com/zeux/pugixml/blob/master/src/pugixml.cpp#L7459
The
xml_buffered_writer
constructor then invokesget_write_encoding
to interpret thatuser_encoding
:https://github.com/zeux/pugixml/blob/master/src/pugixml.cpp#L3753
get_write_encoding
can modify the value ofencoding
(that is subsequently used to initializebuffered_writer.encoding
)https://github.com/zeux/pugixml/blob/master/src/pugixml.cpp#L3618
xml_document::save
proceeds to perform two checks on the unmodified local function parameterencoding
:https://github.com/zeux/pugixml/blob/master/src/pugixml.cpp#L7463 (
encoding != encoding_latin1
)and
https://github.com/zeux/pugixml/blob/master/src/pugixml.cpp#L7477 (
encoding == encoding_latin1
)This implementation could cause a bug in the future, if either of the following becomes true:
encoding_latin1
is modified to a different encoding inget_write_encoding
encoding_latin1
xml_document::save
on any other encoding that is translated either to a different value or from a different value inget_write_encoding
, meaning that the check would then act on the non-interpreted function parameter, possibly triggering an action for the wrong encodingThis patch implements the two checks on the interpreted
buffered_writer.encoding
member variable instead of the unmodified function parameterencoding
.