-
-
Notifications
You must be signed in to change notification settings - Fork 890
Enhance XmpProfile to add XDocument normalization #3047
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
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]