Enhance XmpProfile to add XDocument normalization#3047
Merged
JimBobSquarePants merged 2 commits intomainfrom Jan 22, 2026
Merged
Enhance XmpProfile to add XDocument normalization#3047JimBobSquarePants merged 2 commits intomainfrom
JimBobSquarePants merged 2 commits intomainfrom
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This pull request enhances the XmpProfile class to provide better XML data handling through normalization, improved cloning, and a new constructor for creating profiles from XDocument instances. The changes include renaming GetDocument() to ToXDocument() for API consistency, implementing data normalization to remove UTF-8 BOM and trailing padding bytes, and improving the deep clone implementation.
Changes:
- Added normalization of XMP data to remove UTF-8 BOM and trailing padding bytes (0x00 and 0x0F)
- Added a new constructor accepting
XDocumentthat serializes as UTF-8 without BOM - Renamed
GetDocument()toToXDocument()and improved XML loading with secureXmlReadersettings - Enhanced
DeepClone()to create a true deep copy instead of sharing the same data reference
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 8 comments.
| File | Description |
|---|---|
| src/ImageSharp/Metadata/Profiles/XMP/XmpProfile.cs | Core implementation with new constructor, normalization logic, renamed method, and improved cloning |
| tests/ImageSharp.Tests/Metadata/Profiles/XMP/XmpProfileTests.cs | New tests for XDocument constructor and ToXDocument method, updated deep clone test, and helper method updates |
| tests/ImageSharp.Tests/Metadata/ImageFrameMetadataTests.cs | Updated deep clone test to verify Data arrays are different instances |
| tests/ImageSharp.Tests/Formats/Tiff/TiffMetadataTests.cs | Updated expected data length to account for trimmed padding bytes |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
tests/ImageSharp.Tests/Metadata/Profiles/XMP/XmpProfileTests.cs
Outdated
Show resolved
Hide resolved
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Prerequisites
Description
Fixes #858
See also Discussion #3045
This pull request refactors and improves the
XmpProfileclass in ImageSharp to provide better handling of XML data, normalization of input, and deep cloning. It introduces a new constructor for creating profiles directly fromXDocument, ensures XML data is normalized (removing BOM and padding), and updates the API for converting between byte arrays and XML documents. Associated tests are updated and expanded to cover the new functionality and behaviors.Core enhancements to XMP profile handling:
XmpProfilethat accepts anXDocumentand serializes it as UTF-8 without BOM, enabling direct creation from XML documents.XmpProfileto remove UTF-8 BOM and trailing padding bytes, ensuring consistent internal representation. [1] [2]API and method improvements:
GetDocument()toToXDocument()and improved XML loading to useXmlReaderwith safe settings, preserving whitespace and ignoring DTDs.DeepClone()method to perform a true deep copy of the internal data array, rather than referencing the same memory.Test updates and additions:
XmpProfile(XDocument)constructor andToXDocument()method, and updated helper/test methods to use the new API. [1] [2] [3]