diff --git a/CoreFoundation/Parsing.subproj/CFXMLInterface.c b/CoreFoundation/Parsing.subproj/CFXMLInterface.c index 2702f433e4..9fcac433c7 100644 --- a/CoreFoundation/Parsing.subproj/CFXMLInterface.c +++ b/CoreFoundation/Parsing.subproj/CFXMLInterface.c @@ -495,6 +495,7 @@ static inline xmlChar* _getQName(xmlNodePtr node) { const xmlChar* ncname = node->name; switch (node->type) { + case XML_DOCUMENT_NODE: case XML_NOTATION_NODE: case XML_DTD_NODE: case XML_ELEMENT_DECL: diff --git a/Foundation/XMLNode.swift b/Foundation/XMLNode.swift index 05a265f1e9..a47a6a898c 100644 --- a/Foundation/XMLNode.swift +++ b/Foundation/XMLNode.swift @@ -328,9 +328,13 @@ open class XMLNode: NSObject, NSCopying { return returned == nil ? nil : unsafeBitCast(returned!, to: NSString.self) as String } set { - if case .namespace = kind { + switch kind { + case .document: + // As with Darwin, ignore the name when the node is document. + break + case .namespace: _CFXMLNamespaceSetPrefix(_xmlNode, newValue, Int64(newValue?.utf8.count ?? 0)) - } else { + default: if let newName = newValue { _CFXMLNodeSetName(_xmlNode, newName) } else { diff --git a/TestFoundation/TestXMLDocument.swift b/TestFoundation/TestXMLDocument.swift index f51bd9de96..ad8ea17cff 100644 --- a/TestFoundation/TestXMLDocument.swift +++ b/TestFoundation/TestXMLDocument.swift @@ -40,6 +40,7 @@ class TestXMLDocument : LoopbackServerTest { ("test_optionPreserveAll", test_optionPreserveAll), ("test_rootElementRetainsDocument", test_rootElementRetainsDocument), ("test_nodeKinds", test_nodeKinds), + ("test_sr10776_documentName", test_sr10776_documentName), ] } @@ -625,7 +626,7 @@ class TestXMLDocument : LoopbackServerTest { XCTAssertEqual(try? test(), "plans") } - + func test_nodeKinds() { XCTAssertEqual(XMLDocument(rootElement: nil).kind, .document) XCTAssertEqual(XMLElement(name: "prefix:localName").kind, .element) @@ -640,6 +641,14 @@ class TestXMLDocument : LoopbackServerTest { XCTAssertEqual(XMLDTDNode(xmlString: "")?.kind, .elementDeclaration) XCTAssertEqual(XMLDTDNode(xmlString: #""#)?.kind, .notationDeclaration) } + + func test_sr10776_documentName() { + let doc = XMLDocument(rootElement: nil) + XCTAssertNil(doc.name) + + doc.name = "name" + XCTAssertNil(doc.name) // `name` of XMLDocument is always nil. + } } fileprivate extension XMLNode {