Skip to content

Commit

Permalink
Fixed bug where XmpProfile.FromIXPathNavigable and XmpProfile.FromXDo…
Browse files Browse the repository at this point in the history
…cument would add a xml declaration (#1652).
  • Loading branch information
dlemstra committed Jun 7, 2024
1 parent b38478d commit 4e7a011
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
13 changes: 11 additions & 2 deletions src/Magick.NET.Core/Profiles/Xmp/XmpProfile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public XmpProfile(IXPathNavigable document)
Throw.IfNull(nameof(document), document);

using var memStream = new MemoryStream();
using var writer = XmlWriter.Create(memStream);
using var writer = CreateXmlWriter(memStream);
document.CreateNavigator().WriteSubtree(writer);
writer.Flush();
SetData(memStream.ToArray());
Expand All @@ -49,7 +49,7 @@ public XmpProfile(XDocument document)
Throw.IfNull(nameof(document), document);

using var memStream = new MemoryStream();
using var writer = XmlWriter.Create(memStream);
using var writer = CreateXmlWriter(memStream);
document.WriteTo(writer);
writer.Flush();
SetData(memStream.ToArray());
Expand Down Expand Up @@ -128,6 +128,15 @@ public XDocument ToXDocument()
return XDocument.Load(reader);
}

private static XmlWriter CreateXmlWriter(MemoryStream memStream)
{
var settings = new XmlWriterSettings
{
OmitXmlDeclaration = true,
};
return XmlWriter.Create(memStream, settings);
}

private static byte[] CheckTrailingNULL(byte[] data)
{
Throw.IfNull(nameof(data), data);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public void ShouldCreateProfileFromIXPathNavigable()

var xml = Encoding.UTF8.GetString(profile.ToByteArray());

Assert.Equal(@"<?xml version=""1.0"" encoding=""utf-8""?><test />", xml);
Assert.Equal(@"<test />", xml);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public void ShouldCreateProfileFromIXDocument()

var xml = Encoding.UTF8.GetString(profile.ToByteArray());

Assert.Equal(@"<?xml version=""1.0"" encoding=""utf-8""?><test />", xml);
Assert.Equal("<test />", xml);
}
}
}

0 comments on commit 4e7a011

Please sign in to comment.