Skip to content

Fix crash that occurs when attempting to retrieve the name property of an XMLDocument by making it return nil. #2453

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

Closed
wants to merge 22 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions CoreFoundation/Parsing.subproj/CFXMLInterface.c
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,6 @@ void _CFXMLNodeSetPrivateData(_CFXMLNodePtr node, void* data) {
if (!node) {
return;
}

((xmlNodePtr)node)->_private = data;
}

Expand All @@ -484,10 +483,10 @@ _CFXMLNodePtr _CFXMLNodeProperties(_CFXMLNodePtr node) {
}

CFIndex _CFXMLNodeGetType(_CFXMLNodePtr node) {
if (!node) {
return _kCFXMLTypeInvalid;
if (node) {
return ((xmlNodePtr)node)->type;
}
return ((xmlNodePtr)node)->type;
return _kCFXMLTypeInvalid;
}

static inline xmlChar* _getQName(xmlNodePtr node) {
Expand Down
1 change: 1 addition & 0 deletions Foundation/XMLNode.swift
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,7 @@ open class XMLNode: NSObject, NSCopying {
break
case .namespace:
_CFXMLNamespaceSetPrefix(_xmlNode, newValue, Int64(newValue?.utf8.count ?? 0))

default:
if let newName = newValue {
_CFXMLNodeSetName(_xmlNode, newName)
Expand Down
4 changes: 2 additions & 2 deletions TestFoundation/TestXMLDocument.swift
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,7 @@ class TestXMLDocument : LoopbackServerTest {
do {
try doc.validate()
} catch {
XCTFail("\(error)")
XChttps://github.com/apple/swift-corelibs-foundation/pull/2453/conflict?name=TestFoundation%252FTestXMLDocument.swift&ancestor_oid=f51bd9de96b2ba008d560586ce1742854437931e&base_oid=c5ecbf64cdde4b340781f98aa322748e688b51d9&head_oid=ad8ea17cff29707342411d1e6598480d95b7d579TFail("\(error)")
}

let root = dtd?.elementDeclaration(forName:"root")
Expand Down Expand Up @@ -641,7 +641,7 @@ class TestXMLDocument : LoopbackServerTest {
XCTAssertEqual(XMLDTDNode(xmlString: "<!ELEMENT E EMPTY>")?.kind, .elementDeclaration)
XCTAssertEqual(XMLDTDNode(xmlString: #"<!NOTATION f SYSTEM "F">"#)?.kind, .notationDeclaration)
}

func test_sr10776_documentName() {
let doc = XMLDocument(rootElement: nil)
XCTAssertNil(doc.name)
Expand Down