Skip to content

Conversation

@JimBobSquarePants
Copy link
Member

Prerequisites

  • I have written a descriptive pull-request title
  • I have verified that there are no overlapping pull-requests open
  • I have verified that I am following the existing coding patterns and practice as demonstrated in the repository. These follow strict Stylecop rules 👮.
  • I have provided test coverage for my change (where applicable)

Description

Fixes #858
See also Discussion #3045

This pull request refactors and improves the XmpProfile class in ImageSharp to provide better handling of XML data, normalization of input, and deep cloning. It introduces a new constructor for creating profiles directly from XDocument, 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:

  • Added a new constructor to XmpProfile that accepts an XDocument and serializes it as UTF-8 without BOM, enabling direct creation from XML documents.
  • Implemented normalization of input data in XmpProfile to remove UTF-8 BOM and trailing padding bytes, ensuring consistent internal representation. [1] [2]

API and method improvements:

  • Renamed GetDocument() to ToXDocument() and improved XML loading to use XmlReader with safe settings, preserving whitespace and ignoring DTDs.
  • Improved the DeepClone() method to perform a true deep copy of the internal data array, rather than referencing the same memory.

Test updates and additions:

  • Updated tests to reflect the trimmed data length after normalization and to verify that deep cloning creates a new data array instance. [1] [2] [3] [4]
  • Added new tests for the XmpProfile(XDocument) constructor and ToXDocument() method, and updated helper/test methods to use the new API. [1] [2] [3]

Copy link
Contributor

Copilot AI left a 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 XDocument that serializes as UTF-8 without BOM
  • Renamed GetDocument() to ToXDocument() and improved XML loading with secure XmlReader settings
  • 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.

@JimBobSquarePants JimBobSquarePants merged commit b41bb62 into main Jan 22, 2026
11 checks passed
@JimBobSquarePants JimBobSquarePants deleted the js/xmp-improvements branch January 22, 2026 06:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support for XMP metadata

2 participants