Open
Description
Previous ID | SR-12219 |
Radar | rdar://problem/59655370 |
Original Reporter | @karwa |
Type | Bug |
Environment
Swift-corelibs-foundation:
Darwin Foundation:
macOS 10.15.2 (19C57)
Xcode 11.3.1 (11C504)
Additional Detail from JIRA
Votes | 0 |
Component/s | Foundation |
Labels | Bug |
Assignee | None |
Priority | Medium |
md5: c60cd4ad2b138e7548d0599e363d1c2a
Issue Description:
The swift-corelibs-foundation version of XML DTDs are just entirely broken.
1. Root document not set
let typedefs = XMLDTD()
let document = XMLDocument(rootElement: nil)
document.dtd = typedefs
print(typedefs.rootDocument) // nil -- huh?
This is the same on both Darwin and SCF, but it definitely looks like a bug.
2. Children not set
This means that basic entity substitutions (`&author;` -> "Robert Thompson") also do not work on SCF.
let typedefs = XMLDTD()
let ent = XMLNode.dtdNode(withXMLString:"<!ENTITY author 'Robert Thompson'>") as! XMLDTDNode
typedefs.addChild(ent)
let document = XMLDocument(rootElement: nil)
document.dtd = typedefs
print(typedefs.childCount)
print(typedefs.children?.count)
print("-----")
print(document)
SCF output (note that childCount != children.count):
0
Optional(1)
-----
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<!DOCTYPE PUBLIC "" "">
Darwin output:
1
Optional(1)
-----
<!DOCTYPE [
<!ENTITY author "Robert Thompson">
]>
3. Adding copies of nodes crashes
let typedefs = XMLDTD()
let ent = XMLNode.dtdNode(withXMLString:"<!ENTITY author 'Robert Thompson'>") as! XMLDTDNode
typedefs.addChild(ent)
typedefs.addChild(ent.copy() as! XMLNode)
print(typedefs)
SCF output:
Crash in CFXMLInterface.c:_CFXMLNodeGetPrivateData (node is a null pointer)
Darwin output (no crash):
<!ENTITY author "Robert Thompson">
<!ENTITY (null) "Robert Thompson">
4. Makes a copy of the DTD node when it shouldn't
(note: we're using children.count rather than childCount to work around #2)
let document = XMLDocument(rootElement: nil)
let typedefs = XMLDTD()
document.dtd = typedefs
let ent = XMLNode.dtdNode(withXMLString:"<!ENTITY author 'Robert Thompson'>") as! XMLDTDNode
typedefs.addChild(ent)
print(document.dtd)
print(document.dtd?.children?.count)
SCF output:
Optional(<!DOCTYPE PUBLIC "" "">)
Optional(0)
Darwin output:
Optional( <!ENTITY author "Robert Thompson">
)
Optional(1)