diff --git a/Sources/XMLCoder/Auxiliaries/XMLStackParser.swift b/Sources/XMLCoder/Auxiliaries/XMLStackParser.swift index c18a4fd9..8efa49fe 100644 --- a/Sources/XMLCoder/Auxiliaries/XMLStackParser.swift +++ b/Sources/XMLCoder/Auxiliaries/XMLStackParser.swift @@ -47,7 +47,7 @@ class XMLStackParser: NSObject { errorContextLength: UInt, shouldProcessNamespaces: Bool ) throws -> XMLCoderElement { - let xmlParser = XMLParser(data: data) + let xmlParser = XMLParser(stream: InputStream(data: data)) xmlParser.shouldProcessNamespaces = shouldProcessNamespaces xmlParser.delegate = self diff --git a/Tests/XMLCoderTests/AdvancedFeatures/ErrorContextTest.swift b/Tests/XMLCoderTests/AdvancedFeatures/ErrorContextTest.swift index 2bf69a72..b5bf7857 100644 --- a/Tests/XMLCoderTests/AdvancedFeatures/ErrorContextTest.swift +++ b/Tests/XMLCoderTests/AdvancedFeatures/ErrorContextTest.swift @@ -41,18 +41,10 @@ final class ErrorContextTest: XCTestCase { at line 1, column 7: `ah //>` """ - let column10 = """ - \(underlying.localizedDescription) \ - at line 1, column 10: - `//>` - """ - - #if os(Linux) && swift(<5.4) - // XML Parser returns a different column on Linux and iOS 16+ - // https://bugs.swift.org/browse/SR-11192 + #if os(Windows) || os(Linux) + // Input is fed to the parser as a stream, so the reported column + // is the position of the error rather than the end of the input. XCTAssertEqual(ctx.debugDescription, column7) - #elseif os(Windows) || os(Linux) - XCTAssertEqual(ctx.debugDescription, column10) #else if #available(iOS 16.0, tvOS 16.0, macOS 13.0, *) { XCTAssertEqual(ctx.debugDescription, column7) diff --git a/Tests/XMLCoderTests/Auxiliary/XMLStackParserTests.swift b/Tests/XMLCoderTests/Auxiliary/XMLStackParserTests.swift index 8d8fc242..411f4574 100644 --- a/Tests/XMLCoderTests/Auxiliary/XMLStackParserTests.swift +++ b/Tests/XMLCoderTests/Auxiliary/XMLStackParserTests.swift @@ -158,4 +158,30 @@ class XMLStackParserTests: XCTestCase { XCTAssertEqual(root.elements[1].elements[0].stringValue, "escaped data: <\r\n") XCTAssertEqual(root.elements[2].stringValue, "\n") } + + // libxml2 rejects a single input chunk larger than 10 MB unless + // XML_PARSE_HUGE is set, so the parser must not receive all data at once. + func testDecodeDocumentLargerThan10MB() throws { + struct Catalog: Decodable { + let item: [Item] + } + struct Item: Decodable, Equatable { + let id: Int + let name: String + } + + let count = 100 + let name = String(repeating: "a", count: 110_000) + var xmlString = "" + for i in 0..