Skip to content

Commit

Permalink
Fix issue #3
Browse files Browse the repository at this point in the history
Publish version 1.0.6
  • Loading branch information
lovettchris committed Apr 26, 2023
1 parent 12aad29 commit 503a6cf
Show file tree
Hide file tree
Showing 9 changed files with 79 additions and 31 deletions.
6 changes: 3 additions & 3 deletions src/Common/version.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
<PropertyGroup>
<Company>Lovett Software</Company>
<Copyright>Copyright © Lovett Software</Copyright>
<FileVersion>1.0.5</FileVersion>
<AssemblyVersion>1.0.5</AssemblyVersion>
<Version>1.0.5</Version>
<FileVersion>1.0.6</FileVersion>
<AssemblyVersion>1.0.6</AssemblyVersion>
<Version>1.0.6</Version>
</PropertyGroup>
</Project>
19 changes: 19 additions & 0 deletions src/UnitTests/UnitTest1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,25 @@ public void SimpleFragment()
}
}

[Fact]
public void SideBySideDiffView()
{
using (var col = new TempFileCollection())
{
var xmlSource = col.CreateTempFile("<root><a></a><b><temp/></b></root>");
var xmlChanged = col.CreateTempFile("<root><a id='1'></a><b></b><c></c></root>");

var view = new XmlDiffView();
var options = XmlDiffOptions.IgnoreChildOrder | XmlDiffOptions.IgnoreWhitespace;
var results = view.DifferencesSideBySideAsHtml(xmlSource, xmlChanged, false, options);

var diff = results.ReadToEnd();
Assert.Contains("<span class=\"remove\">&lt;temp</span>", diff);
Assert.Contains("<span class=\"add\">id=\"1\"</span>", diff);
Assert.Contains("<span class=\"add\">&lt;c</span>", diff);
}
}

private string ToComparibleString(XmlDocument doc)
{
// avoid comparing the hash.
Expand Down
2 changes: 1 addition & 1 deletion src/UnitTests/UnitTests.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net48;net6.0</TargetFrameworks>
<TargetFrameworks>net48;net6.0;net7.0</TargetFrameworks>

<IsPackable>false</IsPackable>
</PropertyGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/XmlDiff/XmlDiff.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<Import Project="../Common/version.props" />
<PropertyGroup>
<TargetFrameworks>netstandard2.1;netstandard2.0;net452;net46;net47;net48;netcoreapp3.1;net6.0</TargetFrameworks>
<TargetFrameworks>netstandard2.1;netstandard2.0;net452;net46;net47;net48;netcoreapp3.1;net6.0;net7.0</TargetFrameworks>
<DefineConstants>MEASURE_PERF;TRACE;DESCRIPTORS;DESCRIPTOR_MOVE;DESCRIPTOR_PREFIX_OR_NAMESPACE;VERIFY_HASH_VALUES</DefineConstants>
<PackageId>XmlDiffPatch</PackageId>
<Authors>Chris Lovett</Authors>
Expand Down
36 changes: 14 additions & 22 deletions src/XmlDiff/XmlPatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,16 @@ public void Patch( XmlDocument sourceDoc, XmlReader diffgram )
Patch( ref sourceNode, diffgram );
Debug.Assert( sourceNode == sourceDoc );
}

/// <summary>
/// Reads the XDL diffgram from the diffgramFileName and modifies the original XML document
/// sourceDoc according to the changes described in the diffgram.
/// </summary>
/// <param name="sourceFile">The original xml document</param>
/// <param name="outputStream">The output stream to write results to</param>
/// <param name="diffgram">XmlReader for the XDL diffgram.</param>
public void Patch( string sourceFile, Stream outputStream, XmlReader diffgram )
/// <param name="outputEncoding">The encoding to use in the output stream</param>
public void Patch( string sourceFile, Stream outputStream, XmlReader diffgram, string outputEncoding = "utf-8")
{
if ( sourceFile == null )
throw new ArgumentNullException( "sourceFile" );
Expand All @@ -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();
Expand All @@ -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);
}
}

Expand All @@ -96,7 +99,8 @@ public void Patch( string sourceFile, Stream outputStream, XmlReader diffgram )
/// <param name="sourceReader">The original xml document</param>
/// <param name="outputStream">The output stream to write results to.</param>
/// <param name="diffgram">XmlReader for the XDL diffgram.</param>
public void Patch( XmlReader sourceReader, Stream outputStream, XmlReader diffgram ) {
/// <param name="outputEncoding">The encoding to use in the output stream</param>
public void Patch( XmlReader sourceReader, Stream outputStream, XmlReader diffgram, string outputEncoding = "utf-8") {
if ( sourceReader == null )
throw new ArgumentNullException( "sourceReader" );
if ( outputStream == null )
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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();
}
Expand Down
9 changes: 7 additions & 2 deletions src/XmlDiffView/XmlDiff.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<package >
<metadata>
<id>LovettSoftware.XmlDiff</id>
<version>1.0.5</version>
<version>1.0.6</version>
<authors>Chris Lovett</authors>
<description>A library that compares and merges XML files.</description>
<projectUrl>https://github.com/lovettchris/xmldiff</projectUrl>
Expand All @@ -13,7 +13,6 @@
<icon>icon.png</icon>
<tags>xml;xmldiff</tags>
<dependencies>
<group targetFramework=".NETFramework4" />
<group targetFramework=".NETFramework4.5.2" />
<group targetFramework=".NETFramework4.6" />
<group targetFramework=".NETFramework4.7" />
Expand All @@ -22,6 +21,7 @@
<group targetFramework=".NETStandard2.1" />
<group targetFramework=".netcoreapp3.1" />
<group targetFramework=".net6.0" />
<group targetFramework=".net7.0" />
</dependencies>
</metadata>
<files>
Expand All @@ -45,6 +45,11 @@
<file src="..\XmlDiff\XmlDiffPatch.xml" target="lib\net6.0" />
<file src=".\XmlDiffPatch.View.xml" target="lib\net6.0" />
<file src=".\bin\Release\net6.0\*.json" target="lib\net6.0" />
<!-- .NET Framework 7.0 -->
<file src=".\bin\Release\net7.0\*.dll" target="lib\net7.0" />
<file src="..\XmlDiff\XmlDiffPatch.xml" target="lib\net7.0" />
<file src=".\XmlDiffPatch.View.xml" target="lib\net7.0" />
<file src=".\bin\Release\net7.0\*.json" target="lib\net7.0" />
<!-- .NET Framework 4.8 -->
<file src=".\bin\Release\net48\*.dll" target="lib\net48" />
<file src="..\XmlDiff\XmlDiffPatch.xml" target="lib\net48" />
Expand Down
5 changes: 4 additions & 1 deletion src/XmlDiffView/XmlDiffView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/XmlDiffView/XmlDiffView.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<Import Project="../Common/version.props" />
<PropertyGroup>
<TargetFrameworks>netstandard2.0;netstandard2.1;net452;net46;net47;net48;netcoreapp3.1;net6.0</TargetFrameworks>
<TargetFrameworks>netstandard2.0;netstandard2.1;net452;net46;net47;net48;netcoreapp3.1;net6.0;net7.0</TargetFrameworks>
<PackageId>XmlDiffView</PackageId>
<Authors>Chris Lovett</Authors>
<Product>XmlDiffView 1.0</Product>
Expand Down
29 changes: 29 additions & 0 deletions src/t.htm
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<html><head>
<html><head>
<style TYPE='text/css' MEDIA='screen'>
<!-- td { font-family: Courier New; font-size:14; }
th { font-family: Arial; }
p { font-family: Arial; }
.match { }
.ignore { color:#AAAAAA; }
.add { background-color:yellow; }
.moved { background-color:cyan; color:navy; }
.remove { background-color:red; }
.change { background-color:lightgreen; }
-->
</style></head>
<body>
<table border='0' style='table-layout:fixed;' width='100%'>
<col width='20'><col width='50%'><col width='50%'>
<tr><td><table border='0' width='100%'>
<tr><td colspan='3' align='center'>
<b>Legend:</b> <span class='add'>added</span>&nbsp;&nbsp;
<span class='remove'>removed</span>&nbsp;&nbsp;
<span class='change'>changed</span>&nbsp;&nbsp;
<span class='moved'>moved</span>&nbsp;&nbsp;
<span class='ignore'>ignored</span><br/><br/>
</td></tr>
<tr><td><table border='0'>
<tr><th>C:\Users\clovett\AppData\Local\Temp\tmp39C.tmp</th><th>C:\Users\clovett\AppData\Local\Temp\tmp39D.tmp</th></tr><tr><td colspan='3'><hr size=1></td></tr>
<tr><td colspan='3' align='middle'>Files are different.</td></tr>
<tr><td class="code">1</td><td class="code" style="padding-left: 10pt;"><span class="match">&lt;root</span><span class="match">&gt;</span></td><td class="code" style="padding-left: 10pt;"><span class="match">&lt;root</span><span class="match">&gt;</span></td></tr><tr><td class="code" /><td class="code" style="padding-left: 25pt;"><span class="match">&lt;a</span>&nbsp;<span class="match">/&gt;</span></td><td class="code" style="padding-left: 25pt;"><span class="match">&lt;a</span> <a name="id1"><span class="add">id="1"</span></a><span class="match">/&gt;</span></td></tr><tr><td class="code" /><td class="code" style="padding-left: 25pt;"><span class="match">&lt;b</span><span class="match">&gt;</span></td><td class="code" style="padding-left: 25pt;"><span class="match">&lt;b</span><span class="match">&gt;</span></td></tr><tr><td class="code"><a name="id2">&#xA0;</a></td><td class="code" style="padding-left: 40pt;"><span class="remove">&lt;temp</span><span class="remove">/&gt;</span></td><td class="code" style="padding-left: 40pt;">&nbsp;</td></tr><tr><td class="code">1</td><td class="code" style="padding-left: 25pt;"><span class="match">&lt;/b&gt;</span></td><td class="code" style="padding-left: 25pt;"><span class="match">&lt;/b&gt;</span></td></tr><tr><td class="code"><a name="id3">0</a></td><td class="code" style="padding-left: 25pt;">&nbsp;</td><td class="code" style="padding-left: 25pt;"><span class="add">&lt;c</span><span class="add">/&gt;</span></td></tr><tr><td class="code">1</td><td class="code" style="padding-left: 10pt;"><span class="match">&lt;/root&gt;</span></td><td class="code" style="padding-left: 10pt;"><span class="match">&lt;/root&gt;</span></td></tr></table></table></body></html>

0 comments on commit 503a6cf

Please sign in to comment.