From 27884b21b85b856566626e079e0c62f5a0ea102b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Jab=C5=82o=C5=84ski?= Date: Sun, 21 Jun 2026 20:11:47 +0200 Subject: [PATCH] pass root attributes as list of tuples to preserve ordering This makes XML output deterministic and constant between consecutive encodings --- Sources/XMLCoder/Encoder/XMLEncoder.swift | 2 +- Tests/XMLCoderTests/RootLevetExtraAttributesTests.swift | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Sources/XMLCoder/Encoder/XMLEncoder.swift b/Sources/XMLCoder/Encoder/XMLEncoder.swift index 3444c733..0b8ef62f 100644 --- a/Sources/XMLCoder/Encoder/XMLEncoder.swift +++ b/Sources/XMLCoder/Encoder/XMLEncoder.swift @@ -360,7 +360,7 @@ open class XMLEncoder { /// - throws: An error if any value throws an error during encoding. open func encode(_ value: T, withRootKey rootKey: String? = nil, - rootAttributes: [String: String]? = nil, + rootAttributes: [(key: String, value: String)]? = nil, header: XMLHeader? = nil, doctype: XMLDocumentType? = nil) throws -> Data { diff --git a/Tests/XMLCoderTests/RootLevetExtraAttributesTests.swift b/Tests/XMLCoderTests/RootLevetExtraAttributesTests.swift index 01eb66da..246acd92 100644 --- a/Tests/XMLCoderTests/RootLevetExtraAttributesTests.swift +++ b/Tests/XMLCoderTests/RootLevetExtraAttributesTests.swift @@ -13,9 +13,9 @@ final class RootLevetExtraAttributesTests: XCTestCase { let policy = Policy(name: "test", initial: "extra root attributes") let extraRootAttributes = [ - "xmlns": "http://www.nrf-arts.org/IXRetail/namespace", - "xmlns:xsd": "http://www.w3.org/2001/XMLSchema", - "xmlns:xsi": "http://www.w3.org/2001/XMLSchema-instance", + ("xmlns", "http://www.nrf-arts.org/IXRetail/namespace"), + ("xmlns:xsd", "http://www.w3.org/2001/XMLSchema"), + ("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance"), ] encoder.keyEncodingStrategy = .lowercased