Ensure byte-for-byte results when reading and then writing a file.
Review Request #11763 — Created July 31, 2021 and submitted
When reading a DiffX file using the DOM and then writing it back out,
the contents of the file would change. Since DiffX files are intended to
be a mutable format, we don't want to make any unwanted changes.
There were a few problems leading to this:
1) When reading into a file into a
DiffXobject, default options would
be preserved. This is really a problem for the main
option, which would default to UTF-8 if missing in the DiffX file
content, and would then be written back out. Now, options are cleared
out before they're set.
2) Similarly, if an explicit main
encodingvalue wasn't provided, the
DiffXWriterwould be used. We now explicitly pull out
encodingoption, defaulting to
Noneif not found in the file,
and pass it in to
DiffXWriterwas hard-coding the version being set, and the DOM
therefore wasn't setting a version when writing. Now it will accept
a provided version. While not important right now, this will be
important for compatibility with future spec versions. It's up to
the caller to ensure the version being provided is valid.
Unit tests were added to ensure that we now get byte-for-byte results.
Unit tests pass.