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
DiffX
object, default options would
be preserved. This is really a problem for the mainencoding
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
encoding
value wasn't provided, the
default inDiffXWriter
would be used. We now explicitly pull out
theencoding
option, defaulting toNone
if not found in the file,
and pass it in toDiffXWriter
.2)
DiffXWriter
was 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.
Summary | ID |
---|---|
94542e32e0eee42a25e830aedfc2c9790609b5db |