From 503a6cfbd04e6a825cbbed872d04ca98dc0c4fbc Mon Sep 17 00:00:00 2001 From: Chris Lovett Date: Tue, 25 Apr 2023 20:02:40 -0700 Subject: [PATCH] Fix issue #3 Publish version 1.0.6 --- src/Common/version.props | 6 ++--- src/UnitTests/UnitTest1.cs | 19 ++++++++++++++++ src/UnitTests/UnitTests.csproj | 2 +- src/XmlDiff/XmlDiff.csproj | 2 +- src/XmlDiff/XmlPatch.cs | 36 ++++++++++++------------------ src/XmlDiffView/XmlDiff.nuspec | 9 ++++++-- src/XmlDiffView/XmlDiffView.cs | 5 ++++- src/XmlDiffView/XmlDiffView.csproj | 2 +- src/t.htm | 29 ++++++++++++++++++++++++ 9 files changed, 79 insertions(+), 31 deletions(-) create mode 100644 src/t.htm diff --git a/src/Common/version.props b/src/Common/version.props index 04d332c..4b00586 100644 --- a/src/Common/version.props +++ b/src/Common/version.props @@ -2,8 +2,8 @@ Lovett Software Copyright © Lovett Software - 1.0.5 - 1.0.5 - 1.0.5 + 1.0.6 + 1.0.6 + 1.0.6 \ No newline at end of file diff --git a/src/UnitTests/UnitTest1.cs b/src/UnitTests/UnitTest1.cs index 02f04c3..507bf47 100644 --- a/src/UnitTests/UnitTest1.cs +++ b/src/UnitTests/UnitTest1.cs @@ -60,6 +60,25 @@ public void SimpleFragment() } } + [Fact] + public void SideBySideDiffView() + { + using (var col = new TempFileCollection()) + { + var xmlSource = col.CreateTempFile(""); + var xmlChanged = col.CreateTempFile(""); + + var view = new XmlDiffView(); + var options = XmlDiffOptions.IgnoreChildOrder | XmlDiffOptions.IgnoreWhitespace; + var results = view.DifferencesSideBySideAsHtml(xmlSource, xmlChanged, false, options); + + var diff = results.ReadToEnd(); + Assert.Contains("<temp", diff); + Assert.Contains("id=\"1\"", diff); + Assert.Contains("<c", diff); + } + } + private string ToComparibleString(XmlDocument doc) { // avoid comparing the hash. diff --git a/src/UnitTests/UnitTests.csproj b/src/UnitTests/UnitTests.csproj index dcb7e60..c697775 100644 --- a/src/UnitTests/UnitTests.csproj +++ b/src/UnitTests/UnitTests.csproj @@ -1,7 +1,7 @@ - net48;net6.0 + net48;net6.0;net7.0 false diff --git a/src/XmlDiff/XmlDiff.csproj b/src/XmlDiff/XmlDiff.csproj index 37cd754..0218792 100644 --- a/src/XmlDiff/XmlDiff.csproj +++ b/src/XmlDiff/XmlDiff.csproj @@ -2,7 +2,7 @@ - netstandard2.1;netstandard2.0;net452;net46;net47;net48;netcoreapp3.1;net6.0 + netstandard2.1;netstandard2.0;net452;net46;net47;net48;netcoreapp3.1;net6.0;net7.0 MEASURE_PERF;TRACE;DESCRIPTORS;DESCRIPTOR_MOVE;DESCRIPTOR_PREFIX_OR_NAMESPACE;VERIFY_HASH_VALUES XmlDiffPatch Chris Lovett diff --git a/src/XmlDiff/XmlPatch.cs b/src/XmlDiff/XmlPatch.cs index e1d1147..20591b2 100644 --- a/src/XmlDiff/XmlPatch.cs +++ b/src/XmlDiff/XmlPatch.cs @@ -51,7 +51,7 @@ public void Patch( XmlDocument sourceDoc, XmlReader diffgram ) Patch( ref sourceNode, diffgram ); Debug.Assert( sourceNode == sourceDoc ); } - + /// /// Reads the XDL diffgram from the diffgramFileName and modifies the original XML document /// sourceDoc according to the changes described in the diffgram. @@ -59,7 +59,8 @@ public void Patch( XmlDocument sourceDoc, XmlReader diffgram ) /// The original xml document /// The output stream to write results to /// XmlReader for the XDL diffgram. - public void Patch( string sourceFile, Stream outputStream, XmlReader diffgram ) + /// The encoding to use in the output stream + public void Patch( string sourceFile, Stream outputStream, XmlReader diffgram, string outputEncoding = "utf-8") { if ( sourceFile == null ) throw new ArgumentNullException( "sourceFile" ); @@ -71,6 +72,8 @@ public void Patch( string sourceFile, Stream outputStream, XmlReader diffgram ) XmlDocument diffDoc = new XmlDocument(); diffDoc.Load( diffgram ); + var enc = Encoding.GetEncoding(outputEncoding); + // patch fragment if ( diffDoc.DocumentElement.GetAttribute( "fragments" ) == "yes" ) { NameTable nt = new NameTable(); @@ -80,12 +83,12 @@ public void Patch( string sourceFile, Stream outputStream, XmlReader diffgram ) XmlNodeType.Element, new XmlParserContext(nt, new XmlNamespaceManager(nt), string.Empty, XmlSpace.Default)); - Patch(tr, outputStream, diffDoc); + Patch(tr, outputStream, diffDoc, enc); } } // patch document else { - Patch ( new XmlTextReader( sourceFile ), outputStream, diffDoc ); + Patch ( new XmlTextReader( sourceFile ), outputStream, diffDoc, enc); } } @@ -96,7 +99,8 @@ public void Patch( string sourceFile, Stream outputStream, XmlReader diffgram ) /// The original xml document /// The output stream to write results to. /// XmlReader for the XDL diffgram. - public void Patch( XmlReader sourceReader, Stream outputStream, XmlReader diffgram ) { + /// The encoding to use in the output stream + public void Patch( XmlReader sourceReader, Stream outputStream, XmlReader diffgram, string outputEncoding = "utf-8") { if ( sourceReader == null ) throw new ArgumentNullException( "sourceReader" ); if ( outputStream == null ) @@ -106,13 +110,13 @@ public void Patch( XmlReader sourceReader, Stream outputStream, XmlReader diffgr XmlDocument diffDoc = new XmlDocument(); diffDoc.Load( diffgram ); - - Patch( sourceReader, outputStream, diffDoc ); + + var enc = Encoding.GetEncoding(outputEncoding); + Patch( sourceReader, outputStream, diffDoc, enc); } - private void Patch( XmlReader sourceReader, Stream outputStream, XmlDocument diffDoc ) { + private void Patch( XmlReader sourceReader, Stream outputStream, XmlDocument diffDoc, Encoding enc) { bool bFragments = diffDoc.DocumentElement.GetAttribute( "fragments" ) == "yes"; - Encoding enc = null; if ( bFragments ) { // load fragment @@ -131,18 +135,6 @@ private void Patch( XmlReader sourceReader, Stream outputStream, XmlDocument dif frag.AppendChild( node ); break; } - - if ( enc == null ) { - if ( sourceReader is XmlTextReader ) { - enc = ((XmlTextReader)sourceReader).Encoding; - } - else if ( sourceReader is XmlValidatingReader ) { - enc = ((XmlValidatingReader)sourceReader).Encoding; - } - else { - enc = Encoding.Unicode; - } - } } // patch @@ -154,7 +146,7 @@ private void Patch( XmlReader sourceReader, Stream outputStream, XmlDocument dif if ( frag.FirstChild != null && frag.FirstChild.NodeType == XmlNodeType.XmlDeclaration ) { enc = Encoding.GetEncoding( ((XmlDeclaration)sourceNode.FirstChild).Encoding ); } - XmlTextWriter tw = new XmlTextWriter( outputStream, enc ); + XmlTextWriter tw = new XmlTextWriter(outputStream, enc); frag.WriteTo( tw ); tw.Flush(); } diff --git a/src/XmlDiffView/XmlDiff.nuspec b/src/XmlDiffView/XmlDiff.nuspec index 1332237..8a8e3ff 100644 --- a/src/XmlDiffView/XmlDiff.nuspec +++ b/src/XmlDiffView/XmlDiff.nuspec @@ -2,7 +2,7 @@ LovettSoftware.XmlDiff - 1.0.5 + 1.0.6 Chris Lovett A library that compares and merges XML files. https://github.com/lovettchris/xmldiff @@ -13,7 +13,6 @@ icon.png xml;xmldiff - @@ -22,6 +21,7 @@ + @@ -45,6 +45,11 @@ + + + + + diff --git a/src/XmlDiffView/XmlDiffView.cs b/src/XmlDiffView/XmlDiffView.cs index 0b7cf6a..a57c081 100644 --- a/src/XmlDiffView/XmlDiffView.cs +++ b/src/XmlDiffView/XmlDiffView.cs @@ -514,7 +514,9 @@ public XmlDiffViewResults DifferencesSideBySideAsHtml( this.outputData = new StreamWriter( data, - System.Text.Encoding.Unicode); + System.Text.Encoding.Unicode, + bufferSize: 16000, + leaveOpen: true); bool identicalData = false; try @@ -536,6 +538,7 @@ public XmlDiffViewResults DifferencesSideBySideAsHtml( // Generate the final output using the returned values // from the differences comparison. + data.Seek(0, SeekOrigin.Begin); this.finalOutput = new XmlDiffViewResults(data, identicalData); // return result of comparison diff --git a/src/XmlDiffView/XmlDiffView.csproj b/src/XmlDiffView/XmlDiffView.csproj index df1c0e3..c683f02 100644 --- a/src/XmlDiffView/XmlDiffView.csproj +++ b/src/XmlDiffView/XmlDiffView.csproj @@ -2,7 +2,7 @@ - netstandard2.0;netstandard2.1;net452;net46;net47;net48;netcoreapp3.1;net6.0 + netstandard2.0;netstandard2.1;net452;net46;net47;net48;netcoreapp3.1;net6.0;net7.0 XmlDiffView Chris Lovett XmlDiffView 1.0 diff --git a/src/t.htm b/src/t.htm new file mode 100644 index 0000000..573796e --- /dev/null +++ b/src/t.htm @@ -0,0 +1,29 @@ + + + + + + +
+ +
+ Legend: added   + removed   + changed   + moved   + ignored

+
+ + +
C:\Users\clovett\AppData\Local\Temp\tmp39C.tmpC:\Users\clovett\AppData\Local\Temp\tmp39D.tmp

Files are different.
1<root><root>
<a /><a id="1"/>
<b><b>
 <temp/> 
1</b></b>
0 <c/>
1</root></root>